〇、前情提要
在看b站视频 - 尚硅谷Web前端Ajax教程初学者零基础入门到精通全套完整版(ajax2020最新版),中插了这个知识记录一下。
参考:
-
我的笔记:
【javaweb】b站-尚硅谷Web前端Ajax教程初学者零基础入门到精通全套完整版(ajax2020最新版) 笔记
https://blog.csdn.net/weixin_43210113/article/details/110628389 -
b站视频 - 尚硅谷Web前端Ajax教程初学者零基础入门到精通全套完整版(ajax2020最新版)
https://www.bilibili.com/video/BV1WC4y1b78y?p=2 -
笔记视频链接
链接:https://pan.baidu.com/s/1Wnwb42-AaqAlg6cQ0PRHwg
提取码:3waj
———————————————————————————— -
我的笔记:
【ajax】2.NodeJS的安装与介绍+express框架介绍与基本使用
https://blog.csdn.net/weixin_43210113/article/details/110636188 -
我的笔记:
【ajax】3.GET:AJAX案例准备+AJAX请求的基本操作+AJAX设置请求参数
https://blog.csdn.net/weixin_43210113/article/details/110656792 -
我的笔记:
【ajax】4.POST:AJAX发送POST请求+POST设置请求体
https://blog.csdn.net/weixin_43210113/article/details/110664818 -
我的笔记:
【ajax】5.JSON:服务端响应JSON数据+nodemon自动重启工具安装+Missing write access to /usr/local/lib/node_modules解决方法
https://blog.csdn.net/weixin_43210113/article/details/110792442 -
我的笔记:
【ajax】6.IE缓存问题解决
https://blog.csdn.net/weixin_43210113/article/details/110798325
一、请求超时与网络异常处理
如没有安装过NodeJS和expressjs请看↓
我的笔记:
【ajax】NodeJS的安装与介绍+express框架介绍与基本使用
https://blog.csdn.net/weixin_43210113/article/details/110636188
如没有安装过nodemon请看
我的笔记:
【ajax】5.JSON:服务端响应JSON数据+nodemon自动重启工具安装+Missing write access to /usr/local/lib/node_modules解决方法
https://blog.csdn.net/weixin_43210113/article/details/110792442
5-超时与网络异常.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>请求超时与网络异常</title>
<style>
#result{
width:200px;
height:100px;
border:solid 1px #90b;
}
</style>
</head>
<body>
<button>点击发送请求</button>
<div id="result"></div>
<script>
const btn = document.getElementsByTagName('button')[0];
const result = document.querySelector('#result');
btn.addEventListener('click', function(){
const xhr = new XMLHttpRequest();
xhr.open("GET",'http://127.0.0.1:8000/delay');
xhr.send();
xhr.onreadystatechange = function(){
if(xhr.readyState === 4){
if(xhr.status >= 200 && xhr.status< 300){
result.innerHTML = xhr.response;
}
}
}
})
</script>
</body>
</html>