Ajax No Refresh User Login

Source: Internet
Author: User

<! 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>
&LT;TD width= "A" > User name:</td>
&LT;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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.