Mathias Colpaert
Mathias Colpaert

Reputation: 680

jquery loading screen on ajax call

I would like to show a loading screen in my web application, whenever an ajax call is made with jquery.

Right now, various ajax calls are made: $.getJSON, $.post, $.ajaxFileupload, ...

a Success function is attached to it, that does away with the "loading" screen.

How can I do this in a general way, so a loading screen is shown automatically for each call?

The same question was posted here, but no reply was given.

Upvotes: 0

Views: 2580

Answers (2)

gdoron
gdoron

Reputation: 150313

$.ajaxSetup({
    beforeSend : callback,
    complete : anotherCallback
});

Replace the callback with the function you want to attach to the event.

Upvotes: 1

CodingIntrigue
CodingIntrigue

Reputation: 78605

You can use the $.ajaxStart and $.ajaxStop methods:

$(function() {
  $(document).ajaxStart(function() {
    // Show loading dialog
  });
  $(document).ajaxStop(function() {
    // Hide loading dialog
  });
});

Upvotes: 3

Related Questions