2015-10-09 132 views
1

當我在瀏覽器上使用localhost:8080/SpringServiceJsonSample/rest/service/user/時,我返回json類型的所有數據,但是當我在jQuery網格數據中使用此url數據時未加載,我也使用了調試器,但沒有發現錯誤。Json閱讀器問題

 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, 「名字」: 「與Pradeep」, 「姓氏」: 「與Pradeep」, 「電子郵件」:空},{ 「ID」:2, 「名字」: 「特湖」, 「姓氏」: 「特湖」, 「電子郵件」:空}]

+0

你是否能夠在瀏覽器的網絡部分看到請求到'localhost:8080/SpringServiceJsonSample/rest/service/user /'URL?你會得到200個響應碼嗎? – vijayP

+0

@ vijayP,老兄沒有 –

+0

這意味着這個調用根本不會被調用。請檢查網絡部分,看看爲什麼'/ SpringServiceJsonSample/rest/service/user /'變得最終的URL已經變成# – vijayP

回答

1

您必須修改jsonReader到類似下面的

jsonReader: { 
    repeatitems: true, 
    id: "userid", 
    root: function (obj) { return obj; } 
}, 
loadonce: true, 
gridview: true, 
autoencode: true, 
height: "auto" 

您應該刪除全部index屬性colModel

順便說一下,在jqGrid中不存在選項contentType: "application/json",但是如果您的後端真的需要它,您可以使用ajaxGridOptions:{ contentType: "application/json" }

我會建議你更新jqGrid,你使用的當前版本free jqGrid。此外,還可以添加loadError回調(請參閱the answer),並使用IE/Chrome的Fiddler或Developer Tools來跟蹤jqGrid和服務器之間的HTTP通信。分析HTTP流量有助於理解jqGrid和服務器之間的通信,並快速定位問題的根源。

+0

,兄弟謝謝你,最後我的網格開始加載數據後2天。非常感謝你DUDE奧列格 –

+0

@NaveenMaurya:不客氣! – Oleg