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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM