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