Home >Backend Development >PHP Tutorial >Ajax php user login example without refresh_PHP tutorial
ajax php教程用户无刷新登录实例
<script><br> function userlogin(){<br> var xmlhttp;<br> var str;<br> var sendstr="";<br> try{<br> xmlhttp=new xmlhttprequest();<br> }<br> catch(e){<br> xmlhttp=new activexobject("microsoft.xmlhttp");<br> }<br> xmlhttp.onreadystatechange=function(){<br> if (xmlhttp.readystate==4){<br> if (xmlhttp.status==200){ <br> str = xmlhttp.responsetext; <br> document.getelementbyid("userlogin").innerhtml=str; <br> }else{<br> alert("系统错误,如有疑问,请与管理员联系!"+xmlhttp.status);<br> }<br> }<br> }<br> xmlhttp.open("post","config/userlogin.php",true);<br> xmlhttp.setrequestheader('content-type','application/x-www-form-urlencoded');<br> xmlhttp.send(sendstr); <br> }<br> </script>
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 '用户名或密码不正确!';
}
?>