如果用于jqGrid的您正在使用的数据类型function
与jQuery.agax
然后将您的逻辑放入错误处理程序。唯一的问题是,您必须手动填充网格,并且没有“加载”提示,尽管您可以创建一个提示。
本示例取自调用ASP.NET WCF服务时使用的常用模式,我的结果对象包含分页器的int属性和行集合,这在myGrid.setGridParams
中定义。
datatype: function(postdata) {
$.ajax({
type: "POST",
url: 'SomeService.svc/SomeGetMethod',
data: JSON.stringify(postdata),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(res) {
myGrid.clearGridData();
for (var i = 0; i < res.d.rows.length; i++) {
myGrid.addRowData(i + 1, res.d.rows[i]);
}
myGrid.setGridParam({
page: postdata.page,
lastpage: res.d.total,
records: res.d.records,
total: res.d.total
});
myGrid.each(function() {
if (this.grid) this.updatepager();
});
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// Code to handle error.
}
});
},