当前位置:首页 > PHP教程 > php应用 > 列表

ajax php用户无刷新登录实例

发布:smiling 来源: PHP粉丝网  添加日期:2013-12-23 13:36:03 浏览: 评论:0 
  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. ?> 

Tags: ajax 用户 无刷新 登录 实例

分享到: