中国数据网
http://www.dbchina.net
收藏本页
联系我们
 
ajax用户验证代码 ~ admin

<head>
 <META http-equiv=Content-Type content="text/html; charset=UTF-8">
</head>
<script language="javascript">
 var XMLHttpReq = false;
  //创建XMLHttpRequest对象      
    function createXMLHttpRequest() {
  if(window.XMLHttpRequest) { //Mozilla 浏览器
   XMLHttpReq = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) { // IE浏览器
   try {
    XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
    try {
     XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {}
   }
  }
 }
 //发送请求函数
 function sendRequest(url) {
  createXMLHttpRequest();
  XMLHttpReq.open("GET", url, true);
  XMLHttpReq.onreadystatechange = processResponse;//指定响应函数
  XMLHttpReq.send(null);  // 发送请求
 }
 // 处理返回信息函数
    function processResponse() {
     if (XMLHttpReq.readyState == 4) { // 判断对象状态
         if (XMLHttpReq.status == 200) { // 信息已经成功返回,开始处理信息
             var res=XMLHttpReq.responseXML.getElementsByTagName("res")[0].firstChild.data;
                window.alert(res);               
            } else { //页面不正常
                window.alert("您所请求的页面有异常。");
            }
        }
    }
 // 身份验证函数
    function userCheck() {
  var uname = document.myform.uname.value;
  var psw = document.myform.psw.value;
  if(uname=="") {
   window.alert("用户名不能为空。");
   document.myform.uname.focus();
   return false;
  }
  else {
   sendRequest('login?uname='+ uname + '&psw=' + psw);
  }
}

</script>

<body vLink="#006666" link="#003366" bgColor="#E0F0F8">
<img height="33" src="enter.gif" width="148">
<form action="" method="post" name="myform">
用户名: <input size="15" name="uname"><p>
密&nbsp;&nbsp;码: <input type="password" size="15" name="psw"><p>
<input type="button" value="登录" onclick="userCheck()" >
</form>

Copyright ©2006-2009 DbChina.Net | 鲁ICP备05031207号