当前位置: 移动技术网 > IT编程>脚本编程>Ajax > Ajax传Jsond Mvc后台接收实例

Ajax传Jsond Mvc后台接收实例

2017年12月12日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

//后台
[httppost]
public jsonresult checkstock(ienumerable<pvidscount> pvids)
{
}
public class pvidscount
{
public int pvid { set; get; }
public int count { set; get; }
}
//前台
$(document).ready(function () {
$('#checkout').click(function ()
{
var productidcounntlist = [];
var allpvid = $(".productvariantidall");
$.each(allpvid, function (index, data) {
var productidcounnt = { pvid: data.getattribute("data-id"), count: data.getattribute("data-count")};
productidcounntlist.push(productidcounnt);
});
$.ajax({
url:"@url.action("checkstock")",
type:"post", //复杂对象传值用post,
data: json.stringify ({ pvids: productidcounntlist }), //son.stringify ---must 用来序列化
datatype: "json",
contenttype: 'application/json; charset=utf-8', //must
error: function () {
alert("1");
},
success: function (data) {
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网