How can I display a “waiting” indicator on a web page whilst the http request is being fulfilled by the webserver?

StackOverflow https://stackoverflow.com/questions/2322925

문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top