The execution order of each event in query 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 ( local event )
9.ajaxComplete (Global event)
10.ajaxStop (Global event)
Where global events can be referenced outside of an AJAX-related method (for example, the information for each phase of Ajax execution is displayed somewhere on the page).
The following example shows the order in which each event executes during an AJAX request and how the global Ajax is used.
1 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"2 "Http://www.w3.org/TR/html4/loose.dtd">3 <HTML>4 5 <Head>6 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />7 <Scriptsrc= "Jquery-3.1.0.min.js"></Script>8 <Scripttype= "Text/javascript">9 $(function() {Ten $("#ajaxReuqestID"). Click (function() { One $.ajax ({ A URL:"http://blog.csdn.net/gaoyusi4964238", - Beforesend:function() { - $("#ajaxStateID"). Text ("Berforesend"); the Alert ("Berforesend"); - }, - Success:function() { - $("#ajaxStateID"). Text ("Success"); + Alert ("Success"); - }, + Error:function() { A $("#ajaxStateID"). Text ("Error"); at Alert ("Error"); - }, - Complete :function() { - $("#ajaxStateID"). Text (" Complete"); - Alert (" Complete"); - } in }); - }); to + $("#ajaxStateID"). Ajaxstart (function() { - $( This). Text ("Ajaxstart"); the Alert ("Ajaxstart"); * }). Ajaxsend (function() { $ $( This). Text ("Ajaxsend");Panax Notoginseng Alert ("Ajaxsend"); - }). ajaxsuccess (function() { the $( This). Text ("ajaxsuccess"); + Alert ("ajaxsuccess"); A }). Ajaxerror (function() { the $( This). Text ("Ajaxerror"); + Alert ("Ajaxerror"); - }). Ajaxcomplete (function() { $ $( This). Text ("Ajaxcomplete"); $ Alert ("Ajaxcomplete"); - }). Ajaxstop (function() { - $( This). Text ("Ajaxstop"); the Alert ("Ajaxstop"); - });Wuyi }) the </Script> - </Head> Wu - <Body> About <inputtype= "button"value= "Click to trigger Ajax request"ID= "Ajaxreuqestid" /> $ <DivID= "Ajaxstateid"></Div> - </Body> - - </HTML>
jquery--Global Events