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>