duansha8115 2014-09-23 16:53
浏览 119
已采纳

根据php文件的输出动态加载html

I am trying to load php file's output in html div. And I have tried it with jQuery's ($('div').load(url_here)) method and it's working fine, but my php file is as below:

<?php
for( $i = 0 ; $i < 10 ; $i++ )
{
    echo date('h:i:s').'<br>';
    //flush the output buffer
    flush();
    //send the output buffer
    ob_flush();
   //sleep here
    sleep(1);
} ?>

Now this php file prints a single line every second, but when I load this php in html's div, it takes 10 seconds once the page is loaded and then adds 10 lines all together. I want to load div as php file returns a single line every second. I mean, I want html to respond same as php (i.e. load one line every second, so at 1st second it should load 1st line, at 2nd second it should add 2nd line and so on). So, is it possible? (P.S - I am beginner for this dynamic web)

  • 写回答

2条回答 默认 最新

  • doutun1875 2014-09-23 16:58
    关注

    PHP

       <?php
    
            echo date('h:i:s').'<br>';
    
        ?>
    

    And JS

    <script>
    
    var timer_php = setInterval(function(){
    $("#anydiv").load("abovefile.php");
    },1000);
    
    setTimeout(function(){
    clearTimer(timer_php);
    },10000);
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?