Ajax without refreshing new 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">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> prototype example -- ajax refreshing new user logon </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: simple prototype. js example
Function: ajax allows users to log on without refreshing new users.
From: www.aspprogram.cn
Author: wangsdong
Reprinted. 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 blank! ";
Return false;
Break;
}
Case "2 ":
{
$ ("Msg"). innerHTML = "Incorrect username and password. ";
Return false;
Break;
}
Case "3": $ ("content"). innerHTML = "congratulations, login successful! "; Break;
}
},
On404: function (t)
{
$ ("Msg"). innerHTML = 'error: the submission page cannot be 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>
</Head>

<Body>
<Div id = "content">
<Form action = "#" name = "form1" id = "form1">
<Table>
<Tr>
<Th colspan = "2"> logon </th>
</Tr>
<Tr>
<Td width = "72"> User name: </td>
<Td width = "168"> <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>
</Html>

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.