Home >php教程 >php手册 >ajax php用户无刷新登录实例

ajax php用户无刷新登录实例

WBOY
WBOYOriginal
2016-05-25 16:51:17830browse

<!doctype html> 
<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(&#39;content-type&#39;, &#39;application/x-www-form-urlencoded&#39;);
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文件

<?php
$uid = $_post[&#39;uname&#39;];
$pwd = $_post[&#39;upwd&#39;];
$sql = "select * from tabname where uid=&#39;$uid&#39; and pwd=&#39;$pwd&#39;";
$query = mysql_query($sql);
if (mysql_num_rows($query)) {
    echo &#39;登录成功&#39;;
} else {
    echo &#39;用户名或密码不正确!&#39;;
}
?>


教程地址:

欢迎转载!但请带上文章地址^^

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn