简体   繁体   English

response.status 总是 200

[英]response.status always 200

in my code I want to check if my get request was successful:在我的代码中,我想检查我的获取请求是否成功:

.then(function (response) {
        if (response.status === 200) {
            console.log("ok")
        }
        else{
            console.log("not ok")
        }

even though it says 302 on the.network tab it is always printing "ok" (console.log(response.status) also says 200).即使它在 .network 选项卡上显示 302,它始终打印“ok”(console.log(response.status) 也显示 200)。 Any idea on how to fix this?关于如何解决这个问题的任何想法?

check request readystate and use == instead of ===检查请求就绪状态并使用 == 而不是 ===

then(function (response) {
        if (response.status == 200 && response.readyState == 4) {
            console.log("ok")
        }
        else{
            console.log("not ok")
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM