HTML部分:
<html>
<head>
<scrīptlanguage="javascrīpt">
functionpostRequest(strURL){
varxmlHttp;
if(window.XMLHttpRequest){//ForMozilla,Safari,...
varxmlHttp=newXMLHttpRequest();
}
elseif(window.ActiveXObject){//ForInternetExplorer
varxmlHttp=newActiveXObject("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);
}
functionupdatepage(str){
if(str=="yes"){
alert("WelcomeUser");
}else{
alert("InvalidLogin!Pleasetryagain!");
}
}
functioncall_login(){
varusername=window.document.f1.username.value;
varpassword=window.document.f1.password.value;
varurl="login.php?username="+username+"&password="+password;
postRequest(url);
}
</scrīpt>
</head>
<body>
<Center>
<formname="f1"ōnSubmit="returncall_login();">
<tableborder="0"bgcolor="#CCCCCC"cellspacing="1"cellpadding="3"width="316">
<tr>
<tdalign="left"colspan="2"><b><fontsize="5"color="#000080">Login</font></b></td>
</tr>
<tr>
<tdalign="right"width="124"><b><fontcolor="#000080">User
Name:</font></b></td>
<tdwidth="177"><inputtype="text"name="username"id="user"size="20"value=""/></td>
</tr>
<tr>
<tdalign="right"width="124"><b><fontcolor="#000080">Password:</font></b></td>
<tdwidth="177"><inputtype="password"name="password"size="20"value=""/></td>
</tr>
<tr>
<tdcolspan="2"align="center"><inputtype="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";
}
?>