fetch获取http的response响应码

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>状态码测试</title>
</head>
<body>
</body>
<script>
fetch('www.baidu.com').then(function(response) {
if(response.status == 200){
alert(response.status);
}
}).catch(function(e) {
alert("error");
});
</script>
</html>

 各个状态码的参考:http://tools.jb51.net/table/http_status_code

之后学习一下fetch的相关知识

 fetch相关网站

Fetch API: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

W3C: https://www.w3cschool.cn/fetch_api/fetch_api-w7mt2jzc.html

xhr: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#Constructor

W3C xhr: https://www.w3cschool.cn/ajax/ajax-xmlhttprequest-send.html

posted @ 2019-08-19 20:14  8_9此人多半有病  阅读(2993)  评论(0)    收藏  举报