开发者

jqgrid json data parsererror

开发者 https://www.devze.com 2023-03-19 11:56 出处:网络
My json data returned from server is like this: { \"total\": \"3\", \"page\": \"1\", \"records\": \"21\",

My json data returned from server is like this:

{
    "total": "3",
    "page": "1",
    "records": "21",
    "rows": [
        {
            "id": "6007",
            "cell": [
                "6007",
                "xxx",
                "",
                "22.2"
            ]
        },
        {
            "id": "6008",
            "cell": [
                "6008",
                "xxx",
                "",
                "22.2"
     开发者_如何学C       ]
        },
        {
            "id": "6009",
            "cell": [
                "xxx",
                "xxx",
                "",
                "22.2"
            ]
        },
        {
            "id": "6011",
            "cell": [
                "6011",
                "xxx",
                "",
                "22.2"
            ]
        },
        {
            "id": "6012",
            "cell": [
                "6012",
                "xxx",
                "",
                "22.2"
            ]
        },
        {
            "id": "6013",
            "cell": [
                "6013",
                "xxx",
                "",
                "22.2"
            ]
        },
        {
            "id": "6014",
            "cell": [
                "6014",
                "xxx",
                "",
                "22.2"
            ]
        },
        {
            "id": "6015",
            "cell": [
                "6015",
                "xxx",
                "",
                "22.2"
            ]
        },
        {
            "id": "6016",
            "cell": [
                "6016",
                "xxx",
                "",
                "22.2"
            ]
        },
        {
            "id": "6017",
            "cell": [
                "6017",
                "xxx",
                "",
                "22.2"
            ]
        }
    ]
}

I'm using this jqGrid Declaration in the jquery ready function:

 jQuery('#jqGrid1').jqGrid({
                caption: 'test grid',
                url: 'myurl',
                datatype: 'json',
                colNames: ["Column1", "Column2", "Weight", "NetWeight"],
                colModel: [
                    { "index": "Id", "width": 50, "name": "PartId" },
                    { "index": "Name","width": 100, "name": "CHNPartName" },
                    { "index": "Weight", "width": 75, "name": "Weight" },
                    { "index": "NetWeight", "name": "NetWeight"}
                ],
                viewrecords: true,
                loadError: jqGrid_aspnet_loadErrorHandler,
                pager:jQuery('#Pager1'),
                width: '640'
            });

but occur parsererror in the response , anyone can help me? thanks .


I suppose that you just not set correctly the Content-Type of the HTTP header of the server response. In case of the JSON data it should be "application/json" corresponds to RFC4627. If you use static file to hold the text data you can try to rename the file extension to ".json". Look at the demo which shows that your JSON data can be read by jQuery 1.6.2 without any problem.

0

精彩评论

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

关注公众号