ajax.readyState状态有时候测试总是为1,有时候又正常~~怎么让他稳定点
代码如下var ajax = null;
function createAjax() {
try {
return new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
try {
return new XMLHttpRequest();
} catch (ex) {
}
}
}
function checkUser() {
var name = $("cUser").value;
var url = "checkUser?name=" + name;
ajax = createAjax();
ajax.onreadystatechange = dos;
ajax.open("get", url, true);
ajax.send(null);
}
function dos() {
alert(ajax.readyState);
if (ajax.readyState == 4) {
if (ajax.status == 200) {
if (ajax.responseText == "可以注册") {
$("cUsers").innerHTML = "<img src='imcsjs/g.PNG' id='i' alt=''>";
$("cUsers").style.color = "blue";
} else {
$("cUsers").innerHTML = "<img src='imcsjs/x.PNG' id='i' alt=''>";
$("cUsers").style.color = "red";
}
$("cUsers").innerHTML += ajax.responseText;
} else {
$("cUsers").innerHTML = "正在检测";
}
}
}
------解决方案--------------------
嗯,它要请求嘛,请求后就等待服务器返回,这是要一个过程,要时间的。