Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display a "busy" indicator with jQuery?

How do I display a spinning "busy" indicator at a specific point in a web page?

I want to start/stop the indicator when an Ajax request commences/completes.

Is it really just a matter of showing/hiding an animated gif, or is there a more elegant solution?

like image 569
Tony the Pony Avatar asked Dec 04 '10 19:12

Tony the Pony


People also ask

How to show loading Icon in jQuery?

You can just use the jQuery's . ajax function and use its option beforeSend and define some function in which you can show something like a loader div and on success option you can hide that loader div.


1 Answers

You can just show / hide a gif, but you can also embed that to ajaxSetup, so it's called on every ajax request.

$.ajaxSetup({     beforeSend:function(){         // show gif here, eg:         $("#loading").show();     },     complete:function(){         // hide gif here, eg:         $("#loading").hide();     } }); 

One note is that if you want to do an specific ajax request without having the loading spinner, you can do it like this:

$.ajax({    global: false,    // stuff }); 

That way the previous $.ajaxSetup we did will not affect the request with global: false.

More details available at: http://api.jquery.com/jQuery.ajaxSetup

like image 173
Rodrigo Avatar answered Oct 12 '22 23:10

Rodrigo