2013-10-11 30 views
0

我得到onloading的jqGrid的一个错误如下:的jqGrid不会加载和错误,其无效的XML,但是数据是JSON

load error: Error: Invalid XML: {"d":[{"id":1,"name":"Medical 1","city":"Kiev","instituteTypeId":0},{"id":2,"name":"Medical 2","city":"Kherson","instituteTypeId":0}]}

但是我使用JSON,奥列格劝我打开新的威胁。

jQuery代码是:

mtype: 'POST', 
    contentType: "application/json", 
    url: "dataServices/objects.asmx/InvokeData", 
    ajaxGridOptions: { 
     contentType: 'application/json; charset=utf-8' 
    }, 
    postData: JSON.stringify({q: "med&1"}), 
       loadonce: true, 
       dataType: 'json', 
       jsonReader: { 
        root: function (obj) { 
         alert(obj.d); 
         return obj.d; 
        }, 
        page: "", 
        total: "", 
        records: function (obj) { 
         return obj.d.length; 
        }, 
       }, 
       gridview: true, 
       loadError: function (xhr, status, error) { 
        alert('load error: ' + error); 
       }, 

有任何数据类型= xml或定义的东西....

回答

3

您使用dataType: 'json'这是不对的。 jqGrid的选项有datatypedataType。所以你应该使用dataType: 'json'。未知选项dataType将被忽略,将使用默认选项dataType: 'xml'

此外,我认为你应该只使用jsonReader: { root: "d" }

The demo应该接近你所需要的。所以,你应该这样做

$("#list").jqGrid({ 
    mtype: 'POST', 
    url: "dataServices/objects.asmx/InvokeData", 
    datatype: "json", 
    ajaxGridOptions: { 
     contentType: "application/json; charset=utf-8" 
    }, 
    postData: JSON.stringify({q: "med&1"}), 
    loadonce: true, 
    jsonReader: { root: "d" } 
    ... 
}); 
+0

非常感谢您的帮助,如果你曾经在基辅让我知道会请你美好的夜晚出来))) –

+0

@JaapTerlouw:欢迎您!我很高兴能帮助你。直到现在我从未去过基辅,但是谢谢你的邀请。 – Oleg