0
点赞
收藏
分享

微信扫一扫

发送请求后,取消请求

eelq 2023-03-24 阅读 71

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			  #result {
				  width: 300px;
				  height: 100px;
				  border: 1px solid red;
			  }
		</style>
	</head>
	<body>
		<button>点击发送</button>
		<button>点击取消</button>
	</body>
	<script>
	//当用户点击发送请求后,突然进行了其他操作,则中断请求
		const btm = document.querySelectorAll('button');
		let x = null;
		btm[0].onclick = function(){
			x = new XMLHttpRequest();
			x.open('GET','http://127.0.0.1:8000/delly');
			x.send();
		}
		btm[1].onclick = function(){
			x.abort()
		}
	</script>
</html>

  

发送请求后,取消请求_html

 

举报

相关推荐

0 条评论