国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > php开源 > php教程 > ajax php用户无刷新登录实例

ajax php用户无刷新登录实例

来源:程序员人生   发布时间:2014-04-14 18:06:31 阅读次数:2055次
  1. <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"
  2. <html xmlns="http://www.w3.org/1999/xhtml"
  3. <head> 
  4. <meta http-equiv="content-type" content="text/html; charset=gb2312" /> 
  5. <title>ajax php用户无刷新登录实例</title> 
  6. <script> 
  7. function userlogin(){ 
  8.     var xmlhttp; 
  9.     var str; 
  10.     var sendstr=""
  11.      try{ 
  12.              xmlhttp=new xmlhttprequest(); 
  13.          } 
  14.  catch(e){ 
  15.              xmlhttp=new activexobject("microsoft.xmlhttp"); 
  16.         } 
  17.  xmlhttp.onreadystatechange=function(){ 
  18.           if (xmlhttp.readystate==4){ 
  19.               if (xmlhttp.status==200){   
  20.       str = xmlhttp.responsetext;   
  21.       document.getelementbyid("userlogin").innerhtml=str;  
  22.       }else
  23.       alert("系统错误,如有疑问,请与管理员联系!"+xmlhttp.status); 
  24.     } 
  25.           } 
  26.        } 
  27.  xmlhttp.open("post","config/userlogin.php",true); 
  28.  xmlhttp.setrequestheader('content-type','application/x-www-form-urlencoded'); 
  29.  xmlhttp.send(sendstr);  
  30.  } 
  31. </script> 
  32. </head> 
  33. <body> 
  34. <form id="form1" name="form1" method="post" action=""
  35.   <p> 
  36.     <label for="textfield"></label> 
  37.     <input type="text" name="uname" id="uname" /><span id="userlogin"></span><br /> 
  38. <input type="text" name="upwd" id="upwd" /><span id="upwds"></span> 
  39.   输入用户名</p> 
  40.   <p> 
  41.     <input type="button" name="button" id="button" value="登录" onclick="userlogin();" /> 
  42.   </p> 
  43. </form> 
  44. </body> 
  45. </html> 

userlogin.php文件

  1. <? 
  2. $uid = $_post['uname']; 
  3. $pwd = $_post['upwd']; 
  4. $sql ="select * from tabname where uid='$uid' and pwd='$pwd'"
  5. $query = mysql_query( $sql ); 
  6. if( mysql_num_rows( $query ) ) 
  7.     echo '登录成功'
  8.  } 
  9.  else 
  10.  { 
  11.      echo '用户名或密码不正确!'
  12.   } 
  13. ?> 
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生