gpt4 book ai didi

jquery - 处理ajax中的 session 超时

转载 作者:行者123 更新时间:2023-12-01 03:16:03 25 4
gpt4 key购买 nike

在我的 MVC 应用程序中,我有以下属性来检查登录用户:

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
....
if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
{
filterContext.Result = new Http403Result();
filterContext.HttpContext.Response.StatusCode = 403;
}
...
}

布局.cshtml

    $("body").ajaxError(
function (e, request, settings, exception) {
alert('in');
if (request.status == 403) {
window.location = '@Url.Action("LogOn", "Account", new {area = "", msg = "forbidden", returnUrl = HttpContext.Current.Request.RawUrl})' + window.location.hash;
return;
}
if (request.status == 500) {
window.location = '@Url.Action("AccessDenied", "Error")';
return;
}
if (request.status == 410) {
window.location = '@Url.Action("Deleted", "Error")';
return;
}
window.location = '@Url.Action("Index", "Error")';
});

但由于某种原因,即使抛出 403 代码(来自 ajax 请求),alert("in") 也永远不会被命中:

enter image description here

最佳答案

将 Ajax Error 事件包装在 DOM Ready 函数中

$(document).ready(function () {
$(document).ajaxError(function (e, xhr, settings) {
debugger;
});
});

check here

关于jquery - 处理ajax中的 session 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16080462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com