views:

16

answers:

1

Hello, I am building a new application in Rails 3 and want to implement a "Loading" message that is displayed when an ajax request is fired off and hidden when the response comes back.

I would like to keep it DRY and only specify this functionality in one place, with the ability to override the functionality selectively (for instance, always display the loading message when navigating around the site, but suppress it for things like predictive search).

I'm standardizing on JQuery for this project, although I'm guessing the answer won't be library specific.

Thanks in advance for your feedback!

+2  A: 

jQuery has global ajax handlers such as ajaxStart and ajaxComplete. Once set they fire for all ajax calls.

You can override these global ajax handlers by setting the global property to false on subsequent ajax calls.

redsquare
Excellent, that's what what I was looking for!
Madswede