Cainiao Cai's Ajax review article 3 (no need to log on with Ajax)

Source: Internet
Author: User

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!

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.