level 1
1f2l3y
楼主
var textconns,n;
n = 0 ;
function showHint(str,url) {
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200){
textconns = this.responseText;
alert(textconns);
}else{
n++;
alert("异步失败!"+n);
};
};
xhttp.open("GET",url+"?qintextg="+str,true);
xhttp.send();
};
在写一段无刷回调时,调试这段代码,发现alert("异步失败!"+n); 连续执行了四次,为什么不是执行一次?
2019年11月22日 09点11分
1
n = 0 ;
function showHint(str,url) {
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200){
textconns = this.responseText;
alert(textconns);
}else{
n++;
alert("异步失败!"+n);
};
};
xhttp.open("GET",url+"?qintextg="+str,true);
xhttp.send();
};
在写一段无刷回调时,调试这段代码,发现alert("异步失败!"+n); 连续执行了四次,为什么不是执行一次?