发送请求后,取消请求

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

  

 

posted on 2023-02-08 23:50  爱前端的小魏  阅读(20)  评论(0编辑  收藏  举报

导航