开发者

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

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 reques开发者_StackOverflow社区t 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜