views:

93

answers:

3

Hi,

Background - I have a web application for which a request takes several seconds.

Question - How could I display a "waiting" type indicator (e.g. spinner) to the user after they initiate the request, until the actual HTTP request response comes back from the server?

Notes - I'm assuming this to be a generic web development question, however my web application is a "Ruby on Rails" application.

thanks

+3  A: 

Typically, you'd add a new DOM object (or show an existing one) to the page, potentially via jQuery or some other library, that displays the spinner, and then in whatever callback is fired when the AJAX request completes; you'd have hide the spinner object again.

Amber
so effectively using Javascript to change the page prior to launching the http request correct? that is, you couldn't use a normal link but rather have to orchestrate the two step process via java-script. Do I have this correct?
Greg
Pretty much. Since you don't want the browser to immediately begin loading the new page (but instead merely make the request, but stay on the same page for now), you can't use just a straight url link.
Amber
+1  A: 

First of all, you have a hidden div along with spinner image, when you send the http request, make the div visible and when you receive the response, make it hidden again.

Sarfraz
A: 

The previous posters are correct, you can show an animation, but this isn't ideal for all cases. If you just want to change the cursor, in javascript, you can do this at the start of the request:

document.body.style.cursor = "wait";

and after the request completes:

document.body.style.cursor = "default";    

hope that helps... scott.

ss ulrey