1、ajax 请求
$.post()是jquery一个简单的 POST 请求功能以取代复杂 $.ajax .
参数:
url,[data],[callback],[type]
url:发送请求地址。
data:待发送 Key/value 参数。
callback:发送成功时回调函数。
type:返回内容格式,xml, html, script, json, text, _default。
$.post("/Admin/User/UserAdd", data.field, function (data) { alert(JSON.stringify(data)); });
$.ajax jq的标准ajax请求 data 就是一个json对象 注意 contentType 为 application/json 否则后台接收不到
$.ajax({ type: "post", url: "/Admin/User/UserAdd", dataType: "json", data: data.field, contentType: 'application/json;charset=utf-8',//向后台传送格式 success: function (data) { if (data.success) { $("searchResult").html(data.msg); } else { $("#searchResult").html("出现错误:" + data.msg); } }, error: function (jqXHR) { aler("发生错误:" + jqXHR.status); } });
C# MVC 后台接收
方法一:通过Request.Form
[HttpPost] public ActionResult test() { string id=Request.Form["id"]; return View(); }
[HttpPost] public ActionResult Test(string id) { //id是获取来自View表单POST过来的控件名为id的值 return View(); }
方法三:通过映射到视图数据对象
[HttpPost] public ActionResult Test(TModel model) { string id = model.id; return View(); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。