jQuery ajax - ajaxStart() method

Example

Display the 'loading' indicator when the AJAX request starts:

$("div").ajaxStart(function(){
  $(this).html("<img src='demo_wait.gif' />");
);

Try It Yourself

Definition and Usage

The ajaxStart() method executes a function before sending the AJAX request. It is an Ajax event.

Detailed Explanation

Whenever an Ajax request is sent, jQuery checks if there are any other Ajax requests. If there are none, jQuery triggers the ajaxStart event. At this point, any function registered by .ajaxStart() will be executed.

Syntax

.ajaxStart(function())
Parameters Description
function() Specify the function to be executed when the AJAX request starts.

Example

Display information when the AJAX request starts:

$("#loading").ajaxStart(function(){
  $(this).show();
);