xhr.abort()解决接口重复低啊用问题(鼠标连点)
作者:互联网
1.控制按钮 disable
接口调用的时候 给按钮加disable 属性
接口调通 关闭disable
2. xhr.abort()
let btn = document.getElementById('btn')
let lastXhr
btn.onclick = function(){
if(lastXhr){
lastXhr.abort()
}
lastXhr = getAuthCode()
}
function getAuthCode(){
let xhr = new XMLHttpRequest()
xhr.onreadystatechange = function(){}
xhr.open('get','http://localhost:3000/get_code')
xhr.send()
return xhr
}
标签:function,连点,disable,xhr,abort,lastXhr,btn 来源: https://blog.csdn.net/a378113472/article/details/117951902