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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3816874/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:09:25  来源:igfitidea点击:

jqgrid howto send all rowData in json format to server?

jqueryjsonjqgrid

提问by paul

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

如何将 json 格式的 jqGrid 数据发送到服务器?我必须使用任何外部库或脚本来实现吗?

Thanks!

谢谢!

update1: extra licensePlateNumbershould not be there

update1licensePlateNumber不应该有额外的

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

回答by Oleg

Your approach from your other questionis OK, but jQuery.ajaxhas problems to serialize arrays. The most reliable and standard way (see hereand hereas examples) which I see is to serialize all jqGrid data to JSON (for example with respect of JSON.stringifyfunction:

您从其他问题中得到的方法是可以的,但是jQuery.ajax在序列化数组方面存在问题。我看到的最可靠和标准的方法(参见此处此处作为示例)是将所有 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");
        }
    });
});

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

参数名称jgGridDatacustomData等等,你可以选择任何你喜欢。