weixin_33736832 2016-07-30 22:08 采纳率: 0%
浏览 41

逐一显示每个结果

I have a code which increases a URL parameter in a while loop until $i is equal to 10. When this happens, it will display each number up to 10 (as this is when $i stops increasing) - in this case it would be 1, 2, 3, 4, 5, 6, 7, 8, 9.

The problem with this is that only when $i is equal to 10 does it show 1, 2, 3, 4, 5, 6, 7, 8, 9 - I need it to display the numbers as it happens (rather than waiting for $i to equal 10!).

<div id="here"></div>

<script>
$(document).ready(function(){
        $.ajax({
            type: "POST",
            url: "test2.php",
            success: function(data) { $("#here").html(data);  }
        });
});
</script>

test2.php:

while($content = file_get_contents('https://www.example.com?id='.$i)) {
   if($i !== 10) {
      echo $i;
   }else{
      break;
   }
   $i++;
}
  • 写回答

3条回答 默认 最新

  • weixin_33709364 2016-07-30 22:11
    关注

    There is no stable way to have a PHP script generate output until the script ends.

    If you need a countdown, you can put the while loop in your Javascript and have it call the PHP script with something like:

    test2.php?i=1
    

    then

    test2.php?i=2
    

    etc.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?