Jquery Json读取器问题

Jquery Json读取器问题,jquery,jqgrid,Jquery,Jqgrid,当我在浏览器上使用localhost:8080/SpringServiceJsonSample/rest/service/user/时,我以json类型返回所有数据,但当我在jquery中使用此url时,网格数据未加载,我也使用了调试器,但我没有得到任何错误 jQuery("#grid").jqGrid({ // url: '/Home/SampleGridData/', url: '/SpringServiceJsonSample/re

当我在浏览器上使用
localhost:8080/SpringServiceJsonSample/rest/service/user/
时,我以json类型返回所有数据,但当我在jquery中使用此url时,网格数据未加载,我也使用了调试器,但我没有得到任何错误

       jQuery("#grid").jqGrid({ 
          // url: '/Home/SampleGridData/',
           url: '/SpringServiceJsonSample/rest/service/user/',
           datatype: 'json',
           mtype: 'GET',
           contentType: "application/json" ,
           colNames: ['First Name',  'lastName'],
           colModel: [
             { name: 'firstName', index: 'name', width: 60, align: 'center', editable: true, editrules: { edithidden: false} },                

             { name: 'lastName', index: 'lastName', width: 200, align: 'center', sortable: true, editable: true, edittype: 'text', editrules: { required: true, email: true} },               
           ],
           pager: jQuery('#pager'),
           rowNum: 10,
           rowList: [5, 10, 20, 50],
           sortorder: "asc",
           viewrecords: true,
           caption: 'JqGrid Sample',
           jsonReader: {
               repeatitems: true,
               id: "0",
               cell: "cell",
               rows : "details",
               page : "pageno"
               }
       });

});
我的json值返回如下::-[{“id”:1,“firstName”:“Pradeep”,“lastName”:“Pradeep”,“email”:null},{“id”:2,“firstName”:“Golu”,“lastName”:“Golu”,“email”:null}]


您必须将
jsonReader
修改为如下内容

jsonReader: {
    repeatitems: true,
    id: "userid",
    root: function (obj) { return obj; }
},
loadonce: true,
gridview: true,
autoencode: true,
height: "auto"
您应该
colModel
中删除
index
所有属性

顺便说一下,jqGrid中不存在选项
contentType:“application/json”
,但是如果后端确实需要它,您可以使用
ajaxGridOptions:{contentType:“application/json”}


我建议您将使用的jqGrid更新为的当前版本。另外,添加
loadError
回调(请参阅),并使用IE/Chrome的开发工具跟踪jqGrid和服务器之间的HTTP流量。分析HTTP流量有助于理解jqGrid和服务器之间的通信,并快速定位问题的根源。

您是否能够在浏览器的网络部分看到请求转到
localhost:8080/SpringServiceJsonSample/rest/service/user/
URL?您是否得到了200个响应代码?这意味着该调用根本没有被调用。请查看网络部分并查看
/SpringServiceJsonSample/rest/service/user/
的最终URL格式。您应该在问题后面附上从服务器返回的JSON数据的确切示例。像“我返回json类型的所有数据”这样的信息几乎没有提供任何信息。
jsonReader
应该与数据的格式相对应。此外,知道使用哪个版本的jqGrid是非常重要的。@Oleg,dude,jqGrid 4.1。1@NaveenMaurya:它实际上是3年前发布的jqGrid的复古版。我建议您升级到4.9.2或从CDN使用它(请参阅)。如果您必须使用jqGrid的旧版本,那么确实需要包含精确的JSON响应(2-3行数据就足够了),因为旧版本没有JON格式的自动检测功能。dude非常感谢您最后我的网格在2天后开始加载数据。非常感谢dude Oleg