0
請幫忙。我有搜索舊的問題,但無法找到相關的解決方案。JQGrid - 網格顯示但數據不加載
點擊網格顯示按鈕,但沒有數據加載。
我的網站的回覆:
{"d":"{"totalpages":2,"currpage":1,"totalrecords":15,"rows":[{"id":"110","cell":["110","perform action 1"]},{"id":"112","cell":["112","perform action 2"]},...]}"}
我jQuery代碼:
$("#b4").click(function() {doAjax4();});
function doAjax4() {
$.ajax({
async: false, cache: false,
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebAction.aspx/GetDataTable",
data: "{}",
datatype: "json",
success: function (data) {
$("#mygrid1").jqGrid({
dataType: "json",
type: "POST",
colNames: ['runid', 'action'],
colModel: [{ name: 'runid', index: 'runid' }, { name: 'action', index: 'action' }],
jsonReader: {
root: "rows",
page: "currpage",
total: "totalpages",
records: "totalrecords",
id: "id",
cell: "cell",
repeatitems: true
},
loadonce: true,
viewrecords: true,
gridview: true,
rowList: [5, 10, 50],
caption: "Action Table",
height: 'auto',
//pager: '#pager',
emptyrecords: 'No data for the applied filter'
});
},
error: function (xhr, type, exception) {
alert(xhr.statusText);
}
})
}
感謝您的快速回復和詳細的答案。 **所做的更改 - 它使用jsonstring工作,但我想使用數據類型:「json」&jsonReader。是否有可能或者是方法錯**
更正: 1.現在返回GetDataTable對象 2.錯字更正爲數據類型: 「JSON」 3.刪除異步:假 4。在成功之前,$(「#mygrid1」)。jqGrid({...});添加$(「#mygrid1」)。trigger('reloadGrid'); \t 5. jqgrid選項(a)錯誤更正爲數據類型:「json」。 (b)錯字更正爲mtype。 (c)添加url:「WebAction.aspx/GetDataTable」 6.設置數據類型:「jsonstring」,datastr:data.d. –
@BipoK:不客氣!您可以刪除外部'$ .ajax',並使用帶有選項''datatype:「json」,mtype:「POST」,url:「WebAction.aspx/GetDataTable」的jqGrid。你只需要改變'jsonReader'在所有頂層元素中使用'd.'前綴:'jsonReader:{page:「d.currpage」,total:「d.totalpages」,records:「d.totalrecords」,root:「 d.rows「}' – Oleg
再次感謝您。您在這裏和其他許多SO中的回覆總是有幫助的。您的答案提供瞭解決方案。我還必須添加2個附加選項。這個用法是否正確?添加的選項是[1]'ajaxGridOptions:{contentType:'application/json; charset = utf-8'}'和[2]'serializeGridData:function(postdata){return null;}' –