Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
759 views
in Technique[技术] by (71.8m points)

jquery - jqgrid howto send all rowData in json format to server?

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"
    }
]
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:
" + 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...