lakshmen
lakshmen

Reputation: 29064

Changing the functionality of many ajax calls

Suppose, you're working on a project that does a lot of jQuery.ajax requests. Now you want to display a kind of "loading..." message while a request is running.

How could you do that? You can't change all the $.ajax calls (e.g. there are too many or it's important to have consistent behavior)

Need some guidance on this... Thanks...

Upvotes: 0

Views: 44

Answers (3)

palmplam
palmplam

Reputation: 717

You can listening all ajax events like this :

$("#loading").bind("ajaxSend", function() {
    $(this).show();
}).bind("ajaxComplete", function(){
    $(this).hide();
});

more info in this page : http://docs.jquery.com/Ajax_Events

Upvotes: 0

techfoobar
techfoobar

Reputation: 66663

Check this: http://api.jquery.com/ajaxStart/

In that page, you'll see:

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

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

Upvotes: 0

321X
321X

Reputation: 3185

Check this page: http://api.jquery.com/category/ajax/

You will see .ajaxStart(). Check that page and I'm sure you will figure it out. Since your profile says: 'very keen in learning new things', I'm not going to give it all :-)

Upvotes: 1

Related Questions