tags:

views:

43

answers:

1

I have a page where a lot of ajax action is taking place. I show a spinner to indicate the request is being processed.

Some of those requests long time and some of them are quick. When the response comes quickly then those spinners are more of a nuisance than an aid.

This is what I wanted. Display the spinner only if it has been more than 50ms since the request was submitted.

It means when the request is initiated spinner starts counting time. If a response comes before 50ms then response will make spinner hide.

However if response does not come in 50ms then show spinner.

Is there any plugin already out there that might help me get started.

Thanks

+5  A: 

This can be easily accomplished using vanilla JavaScript. No need for a plug-in.

To show the spinner after 50ms:

var t = setTimeout("showSpinner()", 50);

And then to cancel the timeout if the call succeeds before 50ms (inside the AJAX callback):

clearTimeout(t);
Justin Niessner
I guess OP is looking for a plugin
Ninja Dude
@Avniash - Why supply a plugin when two lines of JavaScript are all he needs? My guess is the OP didn't realize how easy this could be accomplished using Vanilla JavaScript.
Justin Niessner
Yeap. No need of plugin if it can be solved by a couple of lines :-)
Nadal
I guess I don't need to cancel it because response will hide it.
Nadal
@user253470 - That makes it even easier...but it would still be a good idea to cancel it just in case.
Justin Niessner
@Justin Agreed +1 :)
Ninja Dude