IE浏览器是不是handleing 401错误 [英] IE is not handleing 401 error

查看:649
本文介绍了IE浏览器是不是handleing 401错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个部分用来检查,看看是否已经登录Ajax调用。

I have an ajax call that is partly used to check to see if you are logged in.

function userInfo(){
    return $.ajax({
        url: "http://api.itassistteam.com/api/account/isloggedon",
        type: "GET",
        dataType: "json",
        xhrFields: {
            withCredentials: true
        },
        statusCode: {
            401: function(){
                console.log("401 error.");
                deleteCookie();
                window.location.href = "./login.html";
            }
        },
    });
}

在Chrome浏览器,FF和Opera,它重定向到登录页面像它应该,但在IE它什么都不做。当我看到在控制台,它说

In Chrome, FF and Opera, it redirects to the log in page like it's supposed to, but in IE it does nothing. When I look in the console, it says

SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.

任何想法,为什么IE不会采取错误处理程序,并重定向到登录? 401错误。消息未出现在控制台中。

Any idea why IE will not take the error handler and redirect to login? The "401 error." message does not appear in the console.

推荐答案

相反的状态code我用错误。这是你如何让错误,你会得到与

Instead of statusCode I used error. This is how you get the same results with error that you would get with

statusCode : {
    401: function(){...}
}

您做的,

error: function(jqXHR, textStatus, errorThrown){
    if(jqXHR.status == 401){
        ...
    }
}

这是在所有的主流浏览器一致的不同状态code方法巫不使用IE浏览器。通过这种方式,你可以有错误处理特定的错误在IE浏览器。

This is consistent across all major browsers unlike the statusCode method witch doesn't work with IE. This way you can have error handling specific to the error in IE.

这篇关于IE浏览器是不是handleing 401错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆