我有一个获取函数,它接受 URL 并给出响应。
public getHTTPResponse(URL : string) {
fetch(URL).then(function(response) {
return response;
})
}
我尝试在 IF 语句中使用响应。
例如,如果响应为 200
,则它应该为 true。到目前为止我已经:
if (this.getHTTPResponse(item.ListUrl) === )
其中 item.ListUrl
是一个链接。我无法弄清楚运算符(operator)右侧应该有什么来测试响应是否为 200
(或任何其他与此相关的内容)。有什么帮助吗?
最佳答案
response
对象有一个属性status
,其值为整数。尝试这样:
fetch(URL)
.then(function(response) {
if(response.status === 200) {
// do something
};
})
关于javascript - 在 if 语句中使用 Fetch 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53359381/