问题描述
|
我正在通过jquery加载调用controllr动作,该动作非常完美。.它阻止UI,直到数据来自动作为止。
但是当会话超时时,下面的代码将引发未处理的错误...如何在此处处理错误...请帮助...
//block the UI until the request is rendered
$.blockUI({ message: \'<h3><b><img src=\"@Url.Content(\"~/content/images/loading.gif\")\" /> Please wait while the request is being processed...</b></h3>\' });
//load partial view contain grid
$(\'#rptPOSList\').load(\'@Url.Action(\"POSListData\",\"Reports\")\',{ activePOS: ActivePOS,inactivePOS: InActivePOS },function () {
$(\'#contentDiv\').show();
//unblock the UI
$.unblockUI();
});
解决方法
您可以使用
$.ajax
代替.load()
,这可以指定错误处理程序:
$.ajax({
url: \'@Url.Action(\"POSListData\",\"Reports\")\',data: { activePOS: ActivePOS,inactivePOS: InActivePOS },success: function(result) {
$(\'#rptPOSList\').html(result);
$(\'#contentDiv\').show();
$.unblockUI();
},error: function(jqXHR,textStatus,errorThrown) {
alert(\'oops something went wrong\');
}
});
或者,无论AJAX调用是否成功,只要解除UI阻塞,您都可以使用complete
回调:
$.ajax({
url: \'@Url.Action(\"POSListData\",complete: function(jqXHR,textStatus) {
$.unblockUI();
},success: function(result) {
$(\'#rptPOSList\').html(result);
$(\'#contentDiv\').show();
}
});