ck()中怎么让alert(boo+"222222")在alert(boo+"3333")之前显示。
<script type="text/javascript">
var xmlHttpReq;
//创建XMLHTTP对象
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
}else{
xmlHttpReq = new XMLHttpRequest();
}
}
function ck(){
createXMLHttpRequest();
var boo=true;
var name=document.getElementById("name").value;
var pwd=document.getElementById("pwd").value;
if(name==""||pwd==""){
boo =false;
alert("用户名或密码为空!")
}else{
var url="checkLogin?name="+name+"&password="+pwd;
xmlHttpReq.open("POST",url,true);
xmlHttpReq.onreadystatechange =function(){
alert(xmlHttpReq.readyState);
if(xmlHttpReq.readyState == 4){
if(xmlHttpReq.status == 200){
var result = xmlHttpReq.responseText;//将响应信息作为字符串返回
if(result.length==0){
boo=true;
}else{
document.getElementById("resultspan").innerHTML="<b>"+result+"</b>";
boo=false;
}
}
alert(boo+"222222");
};
}
xmlHttpReq.send();
}
alert(boo+"333");
return boo;
}
</script>
xmlHttpReq.open("POST",url,true); 把这个方法改为:
xmlHttpReq.open("POST",url,false); 试试看