<! 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>