weixin_33709609 2015-01-08 08:37 采纳率: 0%
浏览 8

用ajax睡觉

I have a index.php file as below:

    ob_end_clean();
    header("Connection: close");
    ignore_user_abort(true); // optional
    ob_start();
    for($i=1; $i<100; $i++) {
      echo $i . "."; echo ('Text the user will see'); echo '<br>';
    }
    $size = ob_get_length();
    header("Content-Length: $size");
    ob_end_flush();     // Will not work
    flush(); 

    // At this point, the browser has closed connection to the web server

    // Do processing here
    sleep(20);
    file_put_contents ('test.txt', 'test', FILE_APPEND);

If i run on browser localhost/index.php its work, because it can show 'text the user will see' on screen and no need wait 20 seconds. But if i call it with ajax like as below:

$.ajax({
     url: "index.php"
});

It cant show 'text the user will see' for me. And it is work after waited 20 seconds. How can i fix them. Thank you

  • 写回答

1条回答 默认 最新

  • 关注

    I just tried your code using this jquery code in all major browsers and all worked, they closed the connection and displayed result:

    $.ajax({
          url: "index.php"
    }).done(function(data) {
       $('#remote').html(data);
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀