gpt4 book ai didi

javascript - 如何获取 jquery POST 命令的响应状态?

转载 作者:行者123 更新时间:2023-12-02 18:29:52 25 4
gpt4 key购买 nike

我想访问返回状态代码如 200/401 等。我该怎么做?

   var poster=$.post(url, 
{nickname:name, email:mail},function(data) {
alert('Inside poster done');
});

alert(poster.statusCode);

poster.done(function(data){
alert(data);
});

我已经尝试过 How do I get HTTP error response code in Jquery POST 中给出的答案(xhr.status),它只是返回 0。认为实际响应是 Web 控制台中显示的 401。访问 POST 命令的返回状态的正确方法是什么?

最佳答案

虽然成功和错误回调是从响应代码生成的,但你也可以这样做。看这里http://api.jquery.com/jQuery.ajax/

$.ajax({
statusCode: {
404: function() {
alert("code 404");
}
200:function(){
alert("code 200");
}
}
});

关于javascript - 如何获取 jquery POST 命令的响应状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17908261/

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