A little knowledge of jQuery ajax

There are two types of events that Ajax will trigger , one is a local event and the other is a global event:

 

Local events: Called and dispatched via $.ajax.

 

Java code 
  1. $.ajax({  
  2.     beforeSend: function(){  
  3.      // Handle the beforeSend event  
  4.     },  
  5.     complete: function(){  
  6.      // Handle the complete event  
  7.     }  
  8.     // ...  
  9. });  

 

Global events can be bound with bind and unbind with unbind.

 

Java code 
  1. $("#loading").bind("ajaxSend", function(){ //使用bind  
  2.     $(this).show();  
  3. }).ajaxComplete(function(){   //Use ajaxComplete directly  
  4.     $(this).hide();  
  5. });  

 However, sometimes you don't want to use global variables, at this time let global: false

 

Java code 
  1. $.ajax({  
  2.    url: "test.html",  
  3.    global: false,  
  4.    // ...  
  5.  });  

 He also has some sequence of events:

The ajaxStart  global event     starts a new Ajax request and no other ajax requests are in progress at this time.

The beforeSend local event fires      when an Ajax request starts, set the XHR object here. 

ajaxSend global event The global event that fires before the request starts

 

success local event Fired when the request succeeds. When the server returns no errors, the returned data is also free of errors.

 

ajaxSuccess global event global request success

 

error local event Fired only when an error occurs. The two callback functions success and error cannot be executed at the same time.

 

ajaxError global event triggered when an error occurs globally

 

complete local event This event is fired when the request completes, regardless of whether the request succeeded or failed.

 

ajaxComplete global event Triggered when the global request is completed

 

ajaxStop global event Fired when no Ajax is in progress.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326641708&siteId=291194637