Ajax of jquery-global event reference and execution sequence of each event (Global/local)

Source: Internet
Author: User
Turn: http://www.cnblogs.com/shuang121/archive/2012/06/06/2537862.html
Ajax of jquery-global event reference and execution sequence of each event (Global/local)

The event execution sequence in jquery is as follows:

1. ajaxstart (Global Event)

2. beforesend (local event)

3. ajaxsend (Global Event)

4. Success (local event)

5. ajaxsuccess (Global Event)

6. Error (local event)

7. ajaxerror (Global Event)

8. Complete (partial event)

9. ajaxcomplete (Global Event)

10. ajaxstop (Global Event)

Global events can be referenced outside Ajax-related methods (for example, the information of each stage of Ajax execution is displayed somewhere on the page ).

The following example shows the sequence of event execution in an Ajax request and how to use global Ajax.

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"

Http://www.w3.org/TR/html4/loose.dtd>

<HTML>

<Head>

<MCE: script src = "http://code.jquery.com/jquery-latest.js" mce_src = "http://code.jquery.com/jquery-latest.js"> </MCE: SCRIPT>



<MCE: Script Type = "text/JavaScript"> <! --

$ (Function (){

// Click the button and execute the Ajax request
$ ("# Ajaxreuqestid"). Click (function (){

$. Ajax ({

URL: "http://blog.csdn.net/gaoyusi4964238 ",

Beforesend: function (){

$ ("# Ajaxstateid"). Text ("berforesend ");

Alert ("berforesend ");

},

Success: function (){

$ ("# Ajaxstateid"). Text ("success ");

Alert ("success ");

},

Error: function (){

$ ("# Ajaxstateid"). Text ("error ");

Alert ("error ");

},

Complete: function (){

$ ("# Ajaxstateid"). Text ("complete ");

Alert ("complete ");

}

});

});



$ ("# Ajaxstateid"). ajaxstart (function (){

$ (This). Text ("ajaxstart ");

Alert ("ajaxstart ");

}). Ajaxsend (function (){

$ (This). Text ("ajaxsend ");

Alert ("ajaxsend ");

}). Ajaxsuccess (function (){

$ (This). Text ("ajaxsuccess ");

Alert ("ajaxsuccess ");

}). Ajaxerror (function (){

$ (This). Text ("ajaxerror ");

Alert ("ajaxerror ");

}). Ajaxcomplete (function (){

$ (This). Text ("ajaxcomplete ");

Alert ("ajaxcomplete ");

}). Ajaxstop (function (){

$ (This). Text ("ajaxstop ");

Alert ("ajaxstop ");

});

})


// --> </MCE: SCRIPT>
 

</Head>

<Body>

<Input type = "button" value = "click to trigger Ajax request" id = "ajaxreuqestid"/>

<Div id = "ajaxstateid"> </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.