脚本宝典收集整理的这篇文章主要介绍了关于json result的实例代码,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。public JsonResult JsonData()
json方法有一个重构:
PRotected internal JsonResult Json(object data); protected internal JsonResult Json(object data, JsonRequestBehavior behavior);
我们只需要使用第二种就行了,加上一个 json请求行为为Get方式就OK了
public JsonResult GetPersonInfo() { VAR person = new { Name = "张三", Age = 22, Sex = "男" }; return Json(person,JsonRequestBehavior.AllowGet); }
这样一来我们在前端就可以使用Get方式请求了:
view
$.ajax({ url: "/FriendLink/GetPersonInfo", type: "POST", dataType: "json", data: { }, success: function(data) { $("#friendContent").htML(data.Name); } })
<!DOCTYPE html><html><head runat="server"><tITle>Index2</title><script src="\Scripts\jquery-1.10.2.min.js?1.1.11" type="text/javascript"></script><script type="text/javascript">var LOGin = function () { $.ajax({ type: "post", url: "http://localhost:4968/Weathers/JsonData", data: null, success: function (res) { alert(JSON.stringify(res)); }, dataType: "json"}); }</script></head><body><div id="nav"><a href="/Home/Index">ajax+Handler</a>&nbsp; <a>ajax+action</a></div><div><h3>Login</h3><button type="button" onclick="login()">Submit</button></div></body></html>
以上就是关于JSON result的实例代码的详细内容,更多请关注脚本宝典其它相关文章!
以上是脚本宝典为你收集整理的关于json result的实例代码全部内容,希望文章能够帮你解决关于json result的实例代码所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。