jQuery ajax - ajaxStart() method

Example

Display the 'loading...' indicator when an 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 an 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 not, jQuery triggers the ajaxStart event. At this point, any function registered with .ajaxStart() is executed.

Syntax

.ajaxStart(function())
Parameters Description
function() Define a function that runs when an AJAX request starts.

Example

Information displayed when an AJAX request starts:

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