好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php ajax用户登录代码 - 综合实例

php ajax用户登录代码

一款入门级的ajax用户登录代码,有需要的初学者可以参考一下.

login.html 代码如下:

< input   name = username   type = text   />  用户名  < input   name = password   type = password   /> 密码  < input   type = button   value =提交  />  

js代码, 代码如下

function  chk_login(form){       var  username=form.username;       var  password=form.password;       if (username.value ==  "" ){          alert( "用户名不能为空" );          username.focus();           return   false ;      }       if (password.value ==  "" ){          alert( "密码不能为空" );          password.focus();           return   false ;      }       var  url =  'login_chk.php?username=' +username.value+ '&password=' +password.value;      xmlhttp.open( 'get' ,url, true );  //为什么下面加了下面注释掉的代码后,会没反应了,没加就有反应,我的php文件路径都是正确的,也有引入xmlhttprequest.js   xmlhttp.onreadystatechange =  function (){           if (xmlhttp.readyState == 4){               if (xmlhttp.status == 200){                   var  msg = xmlhttp.responseText;                   if (msg ==  "1" ){                      alert( "登陆成功" );                      window.location= 'index.php?name=' +username.value;                  } else   if ((msg ==  "2" ){                      alert( "登陆用户名或密码错误" );                  } else {                      alert(msg);                  }              }          }      }      xmlhttp.send( null );*/  } 

ogin_chk.php,代码如下: <? echo 1?>

因为是测试文件所以没读取数据库了,这里就不写了有需要的朋友可以自己加上读数据库用户名记录,如果存在就返回1就可以了。

查看更多关于php ajax用户登录代码 - 综合实例的详细内容...

  阅读:51次