json传递数组到一般处理程序页,序列化为实体类的方法,可以解决.ENT framework 3.5以前的项目,
3.5以后的项目可以用System.ServiceModel.Web和System.Runtime.Serialization解决,当然也可以使用这种方案。
下面是代码:
JS
function PurchaseAutonomy() { var r = 0; var parmArr = new Array(); $("#dataTb tbody tr").each(function () { var ch = $(this).children().eq(0).children().eq(0).attr("checked"); var num = $(this).children().eq(7).children().eq(0).val(); if (ch == true) { if (IsNum(num)) { return false; } else { parmArr[r] = { PRODUCT_ID: $(this).children().eq(1).text(), PRODUCT_NAME: $(this).children().eq(3).text(), ORG_ID: $(this).children().eq(0).children().eq(2).val(), JS_PRICE: $(this).children().eq(0).children().eq(4).val(), NOS_PRICE: $(this).children().eq(0).children().eq(3).val(), PRODUCT_PRICE: $(this).children().eq(0).children().eq(4).val(), PURCHASE_NUM: $(this).children().eq(7).children().eq(0).val() }; r++; } } }); if (r > 0) { $.MsgBox.Confirm("温馨提示", "生成预订单,确定继续吗?温馨提示", function () { var a = parmArr; $.ajax({ type: "POST", url: "/DataServer/Purchase/PurchaseAdd.ashx", data: { parmArr: JSON.stringify(parmArr),user_id:<%=user_id%>,bm_id:<%=bm_id%> }, datatype:"json", contentType: "application/x-www-form-urlencoded; charset=utf-8", success: function (result) { if (result == "1") { $.MsgBox.Alert("提示", "生成采购计划成功!"); $("#dataTb tbody tr input[type='checkbox']").attr("checked",false); $("#dataTb tbody tr input[name='purchase_num']").val("0"); } else { $.MsgBox.Alert("提示", "生成采购计划失败!"); return false; } } }); }); } else { $.MsgBox.Alert("提示", "请选择要处理的记录!"); return false; } }