<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
/* 超时事件 timeout */
function ajax() {
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", loadHandler);
xhr.addEventListener('timeout',timeoutHandler)//超时事件
xhr.timeout = 30000;
xhr.open('post', 'http://localhost:4010')
xhr.send(JSON.stringify(obj))
}
function timeoutHandler(){
this.abort();
//重联并创建新的通信
}
</script>
</body>
</html>
ajax 超时事件 timeout abort 重连并创建新的通信
最新推荐文章于 2022-08-22 15:51:42 发布