首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ajax睡觉

使用ajax睡觉
EN

Stack Overflow用户
提问于 2015-01-08 16:37:58
回答 1查看 1K关注 0票数 0

我有一个index.php文件,如下所示:

代码语言:javascript
复制
    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);

如果我在浏览器localhost/index.php上运行它,它就会工作,因为它可以在屏幕上显示“用户将看到的文本”,而不需要等待20秒。但如果我使用ajax调用它,如下所示:

代码语言:javascript
复制
$.ajax({
     url: "index.php"
});

它不能显示‘文本,用户将看到’为我。它是等待20秒后的工作。我怎么才能修复它们。谢谢

EN

回答 1

Stack Overflow用户

发布于 2015-01-15 00:18:47

我刚刚在所有主流浏览器中使用此jquery代码测试了您的代码,所有的代码都正常工作,它们关闭了连接并显示了结果:

代码语言:javascript
复制
$.ajax({
      url: "index.php"
}).done(function(data) {
   $('#remote').html(data);
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27835921

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档