.ajaxStart()S2C Home « Ajax « .ajaxStart()

Ajax global start handler.

Description

The .ajaxStart() Ajax method, allows us to register an Ajax Event handler to be called when an Ajax request starts and no other requests are in progress.

  • The .ajaxStart() method callbacks are executed via the ajaxStart event which is triggered when the first starts.

Syntax

Signature Description
.ajaxStart( handler() )Register an Ajax Event handler to be called when an Ajax request starts and no other requests are in progress.

Parameters

Parameter Description Type
handler() The function to be called.
  • The callback is fired in the context of the current jQuery instance, so the this special operator refers to that instance.
Function

Return

A jQuery object.

.ajaxStart( handler() ) ExampleTop

Register an Ajax Event handler to be called when an Ajax request starts and no other requests are in progress.

In the example below when we press the button the first time, we use the .ajaxStart() method to set up a global event handler to be run for each Ajax request. The handler is fired every time an Ajax request is about to be sent (when you click in 'div4' after pressing '#btn4'). In this case the handler outputs a message giving some information about the request to be sent.


$(function(){
  $('#btn4').one('click', function(){
    $(document).ajaxStart(function(event, jqXHR, ajaxSettings) {
       $('#div4').append('Triggered the ajaxStart() global event handler for get7.js<br>');
    });
  });
  $('#div4').on('click', function(){
    $.get( "../js/get7.js" );
  });
});

div4. Some initial text.

Press the button below to action the above code: