AJAX结合PHP代码实现登录

时间:2008-12-22 01:35:07   来源:第二电脑网上收集  作者:第二电脑网

  第二电脑网导读:pt">function postRequest(strURL){var xmlHttp;if(window.XMLHttpRequest){ // For Mozilla, Safari, ...var xmlHttp = new XMLHttpRequest();}else if(window.ActiveXObject){ // For Internet Explorervar xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}xmlHttp.open('POST'...
  正文: HTML部分:

<html>
<head>
<scrīpt language="javascrīpt">
function postRequest(strURL){
var xmlHttp;
if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
var xmlHttp = new XMLHttpRequest();
}
else if(window.ActiveXObject){ // For Internet Explorer
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp.open('POST', strURL, true);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.onreadystatechange = function(){
if (xmlHttp.readyState == 4){
updatepage(xmlHttp.responseText);
}
}
xmlHttp.send(strURL);
}

function updatepage(str){
if(str=="yes"){
alert("Welcome User");
}else{
alert("Invalid Login! Please try again!");
}
}

function call_login(){
var username = window.document.f1.username.value;
var password = window.document.f1.password.value;
var url = "login.PHP?username=" + username + "&password=" +password ;
postRequest(url);
}
</scrīpt>
</head>

<body>
<Center>

<form name="f1" ōnSubmit="return call_login();">
<table border="0" bgcolor="#CCCCCC" cellspacing="1" cellpadding="3" width="316">
<tr>
<td align="left" colspan="2"><b><font size="5" color="#000080">Login</font></b></td>
</tr>
<tr>
<td align="right" width="124"><b><font color="#000080">User
Name:</font></b></td>
<td width="177"><input type="text" name="username" id="user" size="20" value="" /></td>
</tr>
<tr>
<td align="right" width="124"><b><font color="#000080">Password:</font></b></td>
<td width="177"><input type="password" name="password" size="20" value="" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="button" name="a1" value="Login" ōnClick="call_login()"></td>
</tr>
</table>
</form>

</center>
</body>
</html>

PHP脚本部分login.php:

<?
$username=$_GET["username"];
$password=$_GET["password"];
if($username=="admin" && $password=="admin"){
echo "yes";
}else{
echo "No";
}
电脑枝术
?>


来源:http://www.002pc.com/master/College/Programming/PHP/2008-11-27/4114.html

收藏到:

关于《AJAX结合PHP代码实现登录》文章的评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面

随机文章

    SQL Error: select * from ***_ecms_article where classid='86' and checked=1 order by rand() limit 10

顶出来的热门

    SQL Error: select * from ***_ecms_article where classid='86' and checked=1 order by diggtop desc,id desc limit 10
站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td