gpt4 book ai didi

javascript - 401 未经授权的问题

转载 作者:行者123 更新时间:2023-11-28 15:35:48 25 4
gpt4 key购买 nike

我正在使用jQuery.get()方法

$.get('login.php', function(d, textStatus, jqXHR){
//alert(jqXHR.status)
var status = jqXHR.status;
if((status==200)||(status==202)){
window.location.href = 'dashboard.html';
}else if(status==401){
alert('Error in login details')
}else{
alert('Unknown Error')
}
});

工作正常。当 200 和 202 时,它将重定向到仪表板页面。但除了 200 和 202 之外,它会在控制台中传递错误,但不会显示警报。

最佳答案

您需要为 fail 状态添加一些事件处理程序,这将处理 4xx 和 5xx 错误。 success 状态仅处理指示请求成功的 HTTP 代码。来自 http://api.jquery.com/jQuery.get

var jqxhr = $.get( "example.php", function(data, status) {
alert( "success - " + status );
})
.done(function(data, status) {
alert( "second success - " + status );
})
.fail(function(data, status) {
alert( "error - " + status );
})
.always(function(data, status) {
alert( "finished - " + status );
});

关于javascript - 401 未经授权的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25662412/

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