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 triggered.
There are two types of events:
These are callbacks that you can subscribe to within the Ajax request object, like so:
$.ajax({
beforeSend: function(){
// Handle the beforeSend event
},
complete: function(){
// Handle the complete event
}
// ......
}); These events are triggered on the document, calling any handlers which may be listening. You can listen for these events like so:
$(document).bind("ajaxSend", function(){
$("#loading").show();
}).bind("ajaxComplete", function(){
$("#loading").hide();
});
Global events can be disabled for a particular Ajax request by passing in the global option, like so:
$.ajax({
url: "test.html",
global: false,
// ...
}); This is the full list of Ajax events, and in the order in which they are triggered. The indented events are triggered 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.
© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jquery.com/Ajax_Events