jqgrid如何将所有json格式的rowData发送到服务器? [英] jqgrid howto send all rowData in json format to server?

查看:129
本文介绍了jqgrid如何将所有json格式的rowData发送到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

谢谢!

更新1 :不应有多余的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"
    }
]

推荐答案

您从此处

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

参数jgGridDatacustomData等的名称,您可以随意选择.

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

这篇关于jqgrid如何将所有json格式的rowData发送到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆