<!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>
标签:function,请求,取消,发送,点击,onclick,btm From: https://www.cnblogs.com/wsx123/p/17103779.html