I have a few buttons on a page, which when clicked, trigger an ajax call, which then accesses the DB.
After a click, I want the user to not be able to click any of the buttons until the ajax call responses.
But, if possible, I’d like the user to get some indication that the system is in proccess so he won’t think it’s stuck.
Some sort of a simple animation and graying out the page can do the trick, until there’s a response.
Also, I’d like to set a time limit on the ajax call so if there’s no response for, say, 10 seconds, the call will return and give an error message.
What are my options?
I’m working under WordPress, so if it has some nice way to deal with this that’s also an option.
this should do it
js
html
css
demo at http://jsfiddle.net/gaby/X6sDS/1/
With jQuery you can handle ajax events globally, check out http://api.jquery.com/category/ajax/global-ajax-event-handlers/
Try this Jquery plugin to block the user before AJAX call response comes. You can set the timeout in milliseconds in AJAX settings.
http://jquery.malsup.com/block/