ajax验证用户名和密码的实例代码

varxmlrequest;

functioncreateXMLHttpRequest(){

if(window.XMLHttpRequest){

xmlrequest=newXMLHttpRequest();

}

elseif(window.ActiveXObject){

try{

xmlrequest=newActiveXObject("Msxm12.XMLHTTP");

}

catch(e){

try{

xmlrequest=newActiveXObject("Microsoft.XMLHTTP");

}

catch(e){}

}

}

}

functionlogin(){

createXMLHttpRequest();

varuser = document.getElementById("yhm").value;

varpassword = document.getElementById("mm").value;

if(user==""||password==""){

alert("请输入用户名和密码!");

returnfalse;

}

varurl ="check.php?user="+user+"&password="+password;

xmlrequest.open("POST",url,true);

xmlrequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

xmlrequest.onreadystatechange =function(){

if(xmlrequest.readyState == 4){

if(xmlrequest.status==200){

varmsg = xmlrequest.responseText;

if(msg=='1'){

alert('用户名或密码错误!');

user="";

password="";

returnfalse;

}

else{

window.location.href="index1.html";

}

}

}

}

xmlrequest.send("user="+user+"&password="+password);

}

你可能感兴趣的:(ajax验证用户名和密码的实例代码)