jqGrid无法加载,并且错误指出其无效的xml,但是数据是JSON [英] jqGrid does not load and with error that its invalid xml, however data is JSON
问题描述
我在加载jqGrid时出现如下错误:
I get onloading the jqGrid a error as follow:
加载错误:错误:无效的XML:{"d":[{"id":1,"name":医疗 1," city:" Kiev," instituteTypeId:0},{" id:2," name:" Medical 2," city:" Kherson," instituteTypeId:0}]}
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,oleg建议我打开新威胁.
however I use JSON, oleg advised me to open new threat.
jquery代码是:
The jquery code is:
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);
},
没有dataType = xml或任何定义的内容....
There is no dataType= xml or anything defined....
推荐答案
您使用的是dataType: 'json'
,这是错误的. jqGrid具有选项datatype
,没有选项dataType
.因此,您应该使用dataType: 'json'
.未知选项dataType
将被忽略,而将使用默认选项dataType: 'xml'
.
You use dataType: 'json'
which is wrong. jqGrid has the option datatype
and no dataType
. So you should use dataType: 'json'
. Unknown option dataType
will be just ignored and default option dataType: 'xml'
will be used.
另外,我认为您应该只使用jsonReader: { root: "d" }
.
Additionally I think you should use just jsonReader: { root: "d" }
.
演示应该接近您的需求.所以你应该做类似的事情
The demo should be close to what you need. So you should do something like
$("#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" }
...
});
这篇关于jqGrid无法加载,并且错误指出其无效的xml,但是数据是JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!