有时,我们给jqgrid绑定的远端数据获取失败,此时,需要把错误信息反馈给用户展示,如何实现?
可通过jqgrid的 loadError 来处理错误数据的返回。详细如下:
$("#jqGrid").jqGrid({
url: 'TbQueryList',
loadError: function (xhr, status, error) {
var start = xhr.responseText.indexOf("<title>");
var end = xhr.responseText.indexOf("</title>");
abp.message.error(xhr.responseText.substring(start+7, end), "错误信息");
}
});
以上错误的正确返回还需要一个前提:url 端的 TbQueryList 方法能拦截错误信息,并通过throw 统一抛出错误信息。
举例如下:
try
{
result = _reportAppService.ExcuteReportSql(code, rows, page, queryParams, sidx, sord, ref err);
if(err.IsError)
{
throw new Exception(err.Message);
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}