In my current project, I used ajax to fetch data from the server to provide experience like Desktop Application. I wanted to automatically show an indicator when an AJAX request is ongoing, and hide it when there is no such request. So I found the following solution for both the Prototype library and the JQuery library.
Make sure the following HTML is included on every page where AJAX requests are made. (Place it in body of the main layout so that you do not have to repeat this HTML on each page.
The above trick worked for me and hope it works for you guys too.
Helpful links :-