开发者

jqgrid howto send all rowData in json format to server?

开发者 https://www.devze.com 2023-01-18 12:26 出处:网络
how to send jqGrid data in json format to server? DO I have to use any external library or script to achieve that?

how to send jqGrid data in json format to server? DO I have to use any external library or script to achieve that?

Thanks!

update1: extra licensePlateNumber should not be there

[
    {
        "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"
    }
]


Your approach from your other question is OK, but jQuery.ajax has problems to serialize arrays. The most reliable and standard way (see here and here as examples) which I see is to serialize all jqGrid data to JSON (for example with respect of JSON.stringify function:

$("#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");
        }
    });
});

the names of parameters jgGridData, customData and so on, you can choose whatever you like.

0

精彩评论

暂无评论...
验证码 换一张
取 消