jqgrid如何将json格式的所有rowData发送到服务器?

时间:2010-09-28 20:39:48

标签: jquery json jqgrid

如何将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"
    }
]

1 个答案:

答案 0 :(得分:18)

other question的方法没问题,但jQuery.ajax有序列化数组的问题。我看到的最可靠和标准的方法(参见herehere作为示例)是将所有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");
        }
    });
});

参数名jgGridDatacustomData等等,您可以随意选择。