Well, let's just look at the previous example. first create a login.html page to fill in the login information, and then create a DealData. aspx page (of course, it is best to use a general handler here :*. ashx) used to process data.
The Code on the login.html page is as follows:
Copy codeThe Code is as follows:
<Head>
<Title> refreshing logon </title>
<Script src = "Scripts/jquery-1.4.1.js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Function (){
// Bind the global ajaxStart event to the element
$ ("# DivMsg"). ajaxStart (function (){
$ (This). show (); // display the content in the span
})
// Bind the global ajaxStop event to the element
$ ("# DivMsg"). ajaxStop (function (){
Authorization (this).html ("request processing has been completed! "). Hide ();
})
$ ("# BtnSure"). click (function () {// click button event
Var $ name = $ ("# txtName"); // obtain the login name
Var $ pwd = $ ("# txtPwd"); // obtain the password
If ($ name. val ()! = "" & $ Pwd. val ()! = ""){
// Call the Login () method
Login ($ name. val (), $ pwd. val ());
} Else {
If ($ name. val () = "") {// if the login name is not empty
Alert ("login name cannot be blank! ");
$ Name. focus (); // obtain the focus
Return false;
} Else {
Alert ("the password cannot be blank! ");
$ Pwd. focus ();
Return false;
}
}
})
})
Function Login (name, password ){
$. Ajax ({
Type: "POST", // The Data Request Method (post or get). The default value is get.
Url: "DealData. aspx", // address for sending the request (default: Current page)
Data: "action = Login & date =" + new Date () + "& name =" + name + "& pwd =" + password, // data sent to the server
// Data returned after Successful Logon
Success: function (data ){
If (data = "True") {// judge based on the returned value (Note: if it is true, an error occurs !)
Alert ("Logon successful! ");
// Window. location = "1.htm"; page to jump
} Else {
Alert ("Incorrect login name or password! ");
Return false;
}
}
});
}
</Script>
</Head>
<Body style = "text-align: center">
<Div> Logon Name: <input type = "text" id = "txtName" value = ""/> </div>
<Br/>
<Div> password: <input type = "text" id = "txtPwd" value = ""/> </div> <br/>
<Div>
<Input type = "reset" value = "OK" id = "btnSure"/>
</Div>
<Span id = "divMsg" style = "display: none;"> sending request... </span>
</Body>
</Html>
In DealData. aspx, the background code is as follows:
Copy codeThe Code is as follows:
Public partial class ManageData: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
String name = System. Web. HttpUtility. UrlDecode (Request ["name"]); // get the login name
String pwd = System. Web. HttpUtility. UrlDecode (Request ["pwd"]); // obtain the password
Response. Write (Login (name, pwd ));
Response. End ();
}
Private bool Login (string name, string pwd)
{
Bool result = false;
If (name = "coriander" & pwd = "123456 ")
{
Return true;
}
Return result;
}
}
All right, kids shoes. You have a try! You can do the same!