【问题标题】:I want to display a waiting animation while my php page is fetching data from the server我想在我的 php 页面从服务器获取数据时显示等待动画
【发布时间】:2011-08-11 09:49:57
【问题描述】:

当我的 php 页面从服务器获取数据时,我需要显示一个等待动画...怎么做?

【问题讨论】:

  • 您是否使用ajax 与php 脚本进行通信?

标签: php javascript jquery html


【解决方案1】:

如果您使用的是 jQuery Ajax,那么您可以这样做

 $("#loading").ajaxStart(function () {
    $(this).show();
 });

 $("#loading").ajaxStop(function () {
   $(this).hide();
 });

html

<div id="loading" style="display:none;">
    Loading Please Wait....
    <img src="ajax-loader.gif" alt="Loading" />
</div>

http://www.ajaxload.info/获取您的图片

另见此处重复 - How to show loading spinner in jQuery?

【讨论】:

  • 我们可以请停止jQuery默认答案。 jQuery 不是 JavaScript,也不是标准的。最好是更通用的 IMO,而不是强制使用特定的库。同样,如果您提到 mootools、dojo 或原型,这将是同样的问题,有时最简单的就是最好的。
  • 好吧,既然他将他的问题标记为 jQuery,我认为 jQuery 解决方案是可以接受的,但如果您想提供替代方案,那就去吧。无论如何,直到 Raviraja 回来并回答 Arihant 的问题,这只是一个例子,它可能会或可能不会起作用,具体取决于 Rav 正在做什么。
  • 在 ajaxload.info 中提到的道具,漂亮的小网站
【解决方案2】:

假设您的页面上有容器 div 来显示内容。

所以默认情况下,在其中显示加载动画图像,如下所示:

<div id="container" >
    Loading Please Wait....
    <img src="ajax-loader.gif" alt="Searching" />
</div>

查询获取过程完成并且您的Html 内容准备就绪:

divinner HTML 替换为页面内容。

<div id="container" >
   Replace image with Page content after fetching data...
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 2020-07-27
    • 2017-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多