ajax php用戶無刷新登錄實例
來源:程序員人生 發布時間:2014-04-14 18:06:31 閱讀次數:2419次
- <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=gb2312" />
- <title>ajax php用戶無刷新登錄實例</title>
- <script>
- function userlogin(){
- var xmlhttp;
- var str;
- var sendstr="";
- try{
- xmlhttp=new xmlhttprequest();
- }
- catch(e){
- xmlhttp=new activexobject("microsoft.xmlhttp");
- }
- xmlhttp.onreadystatechange=function(){
- if (xmlhttp.readystate==4){
- if (xmlhttp.status==200){
- str = xmlhttp.responsetext;
- document.getelementbyid("userlogin").innerhtml=str;
- }else{
- alert("系統錯誤,如有疑問,請與管理員聯系!"+xmlhttp.status);
- }
- }
- }
- xmlhttp.open("post","config/userlogin.php",true);
- xmlhttp.setrequestheader('content-type','application/x-www-form-urlencoded');
- xmlhttp.send(sendstr);
- }
- </script>
- </head>
- <body>
- <form id="form1" name="form1" method="post" action="">
- <p>
- <label for="textfield"></label>
- <input type="text" name="uname" id="uname" /><span id="userlogin"></span><br />
- <input type="text" name="upwd" id="upwd" /><span id="upwds"></span>
- 輸入用戶名</p>
- <p>
- <input type="button" name="button" id="button" value="登錄" onclick="userlogin();" />
- </p>
- </form>
- </body>
- </html>
userlogin.php文件
- <?
- $uid = $_post['uname'];
- $pwd = $_post['upwd'];
- $sql ="select * from tabname where uid='$uid' and pwd='$pwd'";
- $query = mysql_query( $sql );
- if( mysql_num_rows( $query ) )
- {
- echo '登錄成功';
- }
- else
- {
- echo '用戶名或密碼不正確!';
- }
- ?>
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
------分隔線----------------------------
------分隔線----------------------------