如何将json格式的jqGrid数据发送到服务器?我是否必须使用任何外部库或脚本来实现这一目标?
谢谢!
update1 :额外licensePlateNumber
不应该在那里
[
{
"licensePlateNumber": ""
},
{
"licensePlateNumber": "0000000000000029000721804",
"sku": "795127",
"description": "",
"caseQuantity": "24",
"isHeld": "false",
"expirationDate": "Jul 22, 2010 12:00:00 AM"
},
{
"licensePlateNumber": "0000000000000029000722323",
"sku": "795127",
"description": "",
"caseQuantity": "24",
"isHeld": "false",
"expirationDate": "Jul 22, 2010 12:00:00 AM"
},
{
"licensePlateNumber": "0000000000000029000722669",
"sku": "795127",
"description": "",
"caseQuantity": "24",
"isHeld": "false",
"expirationDate": "Jul 22, 2010 12:00:00 AM"
}
]
答案 0 :(得分:18)
您other question的方法没问题,但jQuery.ajax
有序列化数组的问题。我看到的最可靠和标准的方法(参见here和here作为示例)是将所有jqGrid数据序列化为JSON(例如关于JSON.stringify函数:
$("#sendButton").click(function(){
var gridData = jQuery("#list").getRowData();
var postData = JSON.stringify(gridData);
alert("JSON serialized jqGrid data:\n" + postData);
$.ajax({
type: "POST",
url: "/cpsb/internalOrderList.do",
data : {
jgGridData: postData,
customData: "bla bla"
},
dataType:"json",
contentType: "application/json; charset=utf-8",
success: function(response, textStatus, xhr) {
alert("success");
},
error: function(xhr, textStatus, errorThrown) {
alert("error");
}
});
});
参数名jgGridData
,customData
等等,您可以随意选择。