我正在通过jquery load调用一个控制器动作,这个动作很完美..它阻止了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();
});
答案 0 :(得分:3)
您可以使用$.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');
}
});
或者,如果只是取消阻止UI,无论AJAX调用是否成功,您都可以使用complete
回调:
$.ajax({
url: '@Url.Action("POSListData", "Reports")',
data: { activePOS: ActivePOS, inactivePOS: InActivePOS },
complete: function(jqXHR, textStatus) {
$.unblockUI();
},
success: function(result) {
$('#rptPOSList').html(result);
$('#contentDiv').show();
}
});