发送请求后,取消请求
<!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>