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;}' –