Ajax requests produce a number of different events that you can subscribe to. Here's a full list of the events and in what order they are broadcast.

There are two types of events:

Local Events

These are callbacks that you can subscribe to within the Ajax request object, like so:

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

Global Events

These events are broadcast to all elements in the DOM, triggering any handlers which may be listening. You can listen for these events like so:

 $("#loading").bind("ajaxSend", function(){
   $(this).show();
 }).bind("ajaxComplete", function(){
   $(this).hide();
 });

Global events can be disabled for a particular Ajax request by passing in the global option, like so:

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

Events

This is the full list of Ajax events that are broadcast, and in the order in which they are broadcast. The indented events are broadcast for each and every Ajax request (unless a global option has been set). The ajaxStart and ajaxStop events are events that relate to all Ajax requests together.