【www.gdgbn.com--js教程】


ajax实现登陆验证

js文件如下:



var xmlHttp;
function IMG1_onclick() {
  CheckIsValid();
}
function CheckIsValid()
{
  CreatXmlHttpRequest();
  var userName=document.getElementById("AdminText");
  var passWord=document.getElementById("AdminPasswordText");
  var url="CheckLogin.aspx?userName="+escape(userName.value)+"&passWord="+escape(passWord.value);
  xmlHttp.open("GET",url,true);
  xmlHttp.onreadystatechange=callback;
  xmlHttp.send(null);
}
function CreatXmlHttpRequest()
{
try {
   xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
   try {
     xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (e2) {
     xmlHttp = false;
   }
}
if (!xmlHttp && typeof XMLHttpRequest != ""undefined"") {
   xmlHttp = new XMLHttpRequest();
}
}
function callback()
{
  if(xmlHttp.readyState==4)
  {
    if(xmlHttp.status==200)
    {
      var mes=xmlHttp.responseXML.getElementsByTagName("message")[0].firstChild.data;
      var val=xmlHttp.responseXML.getElementsByTagName("passed")[0].firstChild.data;
      setMessage(mes,val);
    }
  }
}

本文来源:http://www.gdgbn.com/wangyezhizuo/14221/