2

The problem is the following. We have lots of ajax call via $.ajax function. Now I would like to add some loader indicator that will show up when ajax call started and disappear when ajax call finishes. Is there a way to extend jquery's $.ajax function with this kind of behavior.

Of course it is always possible to search for all $.ajax in code and add necessary behavior but I feel somehow lazy to do this.

2 Answers 2

3

You have jQuery functions for that. Take this example:

<div id="loading">Loading...</div>

Now the jQuery code:

$(document).ready(function() {

  $().ajaxStart(function() { $('#loading').show(); });
  $().ajaxStop(function() { $('#loading').hide(); });

});

ajaxStart detects that an ajax call is being made and executes a function. ajaxStop will detect that the ajax call has ended and will execute a function. This works with any ajax call in your code.

Sign up to request clarification or add additional context in comments.

Comments

1

You use ajaxStart/ajaxStop. may find this article to be of help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.