会话超时处理

时间:2011-05-26 08:34:38

标签: jquery asp.net asp.net-mvc-3

我正在通过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();
    });

1 个答案:

答案 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();
    }
});