在jqGrid中显示我的json数据时遇到了麻烦。在jqGrid中加载JSON数据
我在这个论坛上搜索了很多,并尝试过各种形式使它工作。我很抱歉,如果这已经得到解答,但我真的需要帮助。
在服务器页面我只是用JavaScriptSerializer发送数据和jsonreader函数的默认参数(这个工作确定)。
我现在需要进行分页,并改变了我的服务器网页代码与SIDX,SORD,页,行参数工作。
从服务器生成的字符串如下所示:
{"total":"344","page":"1","records":"8577","root":[{"Id":"1","SerialNumber":"132","Name":"ServerName"},...]}
这里是我的jQuery代码:
$("#list").jqGrid({
datatype: "json",
mtype: 'GET',
url:'https://server/handlerpage.ashx',
colNames:['Id','SerialNumber','Name'],
colModel :[
{name:'Id', index:'Id', jsonmap:"Id", width:20},
{name:'Name', index:'Name', jsonmap:"Name", width:120},
{name:'SerialNumber', index:'SerialNumber', jsonmap:"SerialNumber", width:100}],
jsonreader: {repeatitems:false,id:'Id',root:'root'},
pager: '#pager',
rowNum:25,
rowList:[25,50,75,100],
sortname: 'Id',
viewrecords:true,
gridview: true,
height:"400",
width:"700",
caption: 'Select from existing server',
loadtext:'Loading, please wait'
}).navGrid("#pager", { edit: false, add: false, search: true, del: false });
您的代码中的主要错误是使用'jsonreader'而不是'jsonReader'。你可以删除所有'jsonmap'属性和'index'。我建议你另外不要使用像''https:// server/handlerpage.ashx'这样的'url'。对应于Ajax [相同来源策略](http://en.wikipedia.org/wiki/Same_origin_policy),您必须使用与当前页面相同的“https:// server /”前缀。所以你最好使用'url:'handlerpage.ashx''或'url:'/ handlerpage.ashx''。 – Oleg 2012-03-27 19:48:03
谢谢Oleg,我测试了jsonReader(大写R),它确实有效。也改变了网址以遵守政策并且也工作。 – fabianmunoz 2012-03-27 21:02:56
不客气!有时候错误非常小(只有一个字母),但正因为如此,可能很难找到它。 – Oleg 2012-03-27 21:09:35