xmlHttp.readyState=-2是几个意思?
之前那和帖子问题是js return false后继续执行action,我找了下原因,把 readyState错误码打印出来一看是-2.。。不知道怎么办了,是if else 哪里出错了么?我是新手,希望大家帮帮忙啊!
js:
function checkuser() {
var username = f1.username.value;
var userpassword = f1.userpassword.value;
var xmlHttp;
if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp.open("GET", "com/servlet/ValidateUsernameServlet?username=" + username, true);
xmlHttp.send(null);
xmlHttp.onreadystatechange =function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
if (xmlHttp.responseText == "true") {
document.getElementById("usernameid").innerHTML = "√";
return true;
}else {
document.getElementById("usernameid").innerHTML = "<font color='red'>"+"昵称或密码错误!"+ "</font>";
f1.username.focus();
return false;
}
} else {
alert("错误码:" + xmlHttp.readyState);
f1.username.focus();
return false;
}
}
}
jsp:
<form
id="f1" style=" position:fixed;top:90px;left:415.5px;width:500px;height:250px;"
class="navbar-form navbar-left" role="form" action="<%=basePath %>login" method="put" onsubmit="return checkuser()" >
<!-- <DIV style="background: rgb(255, 255, 255); margin: -100px auto auto; border: 1px solid rgb(231, 231, 231); border-image: none; width: 400px; height: 200px; text-align: center;"> -->
<div class="input-group1">
<span class="input-group-addon">昵称:</span>
<input id="username" name="username" type="text" class="input"
placeholder="1-10个汉字、字母、数字组合" size="31" aria-describedby="basic-addon1" onblur="checkusername()" >
<span id="usernameid"></span>
</div>
<div class="input-group2" id="userpasswordiv">
<span class="input-group-addon">密码:</span>
<input name="userpassword" type="password" class="input"
placeholder="6-12位(必须包含数字及字母)" size="31" aria-describedby="basic-addon1" onblur="checkuserpassword()" >
<span id="userpasswordid"></span>
</div>
<button type="submit" class="btn btn-default" style="position: fixed;top:255px;left:465.5px;width:200px;height:35px; ">登录</button>
</form>