【问题标题】:How can I make AJAX animate my progress bar?如何让 AJAX 为我的进度条设置动画?
【发布时间】:2014-03-03 11:18:44
【问题描述】:

我有一个 PHP 页面,显示 1%...2%.....3%..... 等带有输出缓冲区。

如何让 ajax 检测这些更改并让它们反映在进度条的宽度 CSS 属性中?

$.ajax({
        type: "POST",
       url: "iopio.php",
       success: function(html){ 

         if (html != '100%') {

            $('#mainBar').animate({width:html});
            $('#status').text("Working.");

         }
        }



    });

【问题讨论】:

标签: php ajax


【解决方案1】:

你正在做的是阅读内容一次,因此你每次都会得到一个静态答案,使用这种技术你会想要设置一个循环的 ping 事件来保持更新,如下所示:

function pingProgress(){

    $.ajax({
        type: "POST",
        url: "iopio.php",
        success: function(html){ 

            if (html != '100%') {
                $('#mainBar').animate({width:html});
                $('#status').text("Working.");

                pingProgress();
            }
        }

    });

}
//Start loop
pingProgress();

这专门循环调用函数,直到达到 100%。要保存数据,您可以考虑添加超时功能等。

【讨论】:

  • 你必须在某处运行 pingProgress() 才能开始循环,现在添加
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-03
  • 2015-03-23
  • 2021-11-17
  • 2016-02-24
  • 2011-06-30
相关资源
最近更新 更多