<!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