Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show ajax loading indicator not immediately but after a delay

Tags:

jquery

ajax

My current web app project makes heavy use of ajax calls. Most of them are fast and respond almost immediately. So, showing ajax loader all the time is not necessary. But I want to show an ajax loader when ajax calls take longer then 250ms (or so). Otherwise the users might be confused and keep clicking on links over and over again. :)

Any ideas how to accomplish that using jQuery?

like image 368
Oliver Andrich Avatar asked Apr 12 '09 09:04

Oliver Andrich


2 Answers

I have no previous experience with jQuery but to achieve a simple delay to execution of some code, just use this:

setTimeout ("foo()", 250);

where foo() is the function responsible for loading... indication.

like image 159
Peter Perháč Avatar answered Sep 23 '22 03:09

Peter Perháč


Can you use a Javascript timer to trigger after 250ms to display your 'loading...' message ?

Activate this on ajaxSend(), and disable it on ajaxComplete() (and clear the 'loading...' message if reqd), and so the implementation should be transparent to whatever Ajax calls you make.

like image 24
Brian Agnew Avatar answered Sep 22 '22 03:09

Brian Agnew