<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>prototype example--ajax No refresh user login </title>
<style type= "Text/css" >
body{font-size:13px;}
#msg {color:red;text-align:left;font-size:14px;}
. txt{width:120px;border:1px solid #000;}
</style>
<script src= "Prototype.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
/*
Title: A simple Prototype.js example
Function: Ajax No Refresh User Login
From: www.111cn.net
Author: Wangsdong
Reprint please keep this information, thank you
*/
function Chkfrom (obj)
{
$ ("msg"). innerhtml= "";
var opt = {
Method: ' Get ',
Onsuccess:function (t)
{
M=t.responsetext;
Switch (m)
{
Case "1":
{
$ ("msg"). innerhtml= "username and password cannot be empty!" ";
return false;
Break
}
Case "2":
{
$ ("msg"). Innerhtml= "the wrong username and password." ";
return false;
Break
}
Case "3": $ ("Content"). Innerhtml= "Congratulations, login success!" ";
}
},
On404:function (t)
{
$ ("msg"). Innerhtml= ' ERROR: No submit page found! '
return false;
},
Onfailure:function (t)
{
$ ("msg"). Innerhtml= ' ERROR: ' + t.status + t.statustext;
return false;
},
Asynchronous:true
}
var ajax=new ajax.request (' Login.asp? ') +getrequestbody (obj), opt);
}
function Getrequestbody (oform)
{
var aparams = new Array ();
for (Var i=0 i < oForm.elements.length; i++) {
var Sparam = encodeURIComponent (oform.elements[i].name);
Sparam + = "=";
Sparam + + encodeuricomponent (oform.elements[i].value);
Aparams.push (Sparam);
}
Return Aparams.join ("&");
}
</script>
<body>
<div id= "Content" >
<form action= "#" Name= "Form1" Id= "Form1" >
<table>
<tr>
<th colspan= "2" > Login </th>
</tr>
<tr>
<TD width= "A" > User name:</td>
<TD width= "><input" type= "text" name= "username" id= "username" class= "txt" >
</td>
</tr>
<tr>
<td> Password:</td>
<td><input type= "password" name= "password" id= "password" class= "TXT" >
</td>
</tr>
<tr>
<td> </td>
<td><input type= "button" name= "Submit" id= "submit" value= "Login" onclick= "Javascript:chkfrom (this.form)" > </td></tr>
</table>
</form>
</div>
<div id= "MSG" ></div>
</body>