.ajaxStart()

Register a handler to be called when the first Ajax request begins. This is an Ajax Event.

.ajaxStart(function())🡢 jQuery

function() FunctionThe function to be invoked.

Whenever an Ajax request is about to be sent, jQuery checks whether there are any other outstanding Ajax requests. If none are in progress, jQuery triggers the ajaxStart event. Any and all handlers that have been registered with the .ajaxStart() method are executed at this time.

To observe this method in action, set up a basic Ajax load request:

<div class="trigger">Trigger</div>
<div class="result"></div>
<div class="log"></div>

Attach the event handler to any element:

$(document).ajaxStart(function () {
  $(".log").text("Triggered ajaxStart handler.");
});

Now, make an Ajax request using any jQuery method:

$(".trigger").click(function () {
  $(".result").load("ajax/test.html");
});

When the user clicks the element with class trigger and the Ajax request is sent, the log message is displayed.

Show a loading message whenever an Ajax request starts (and none is already active).

HTML
$(document).ajaxStart(function () {
  $("#loading").show();
});
DEMO

Looking for a Web Developer?

👋

Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at jobs@jqapi.com :)