我有一个index.php文件,如下所示:
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调用它,如下所示:
$.ajax({
url: "index.php"
});它不能显示‘文本,用户将看到’为我。它是等待20秒后的工作。我怎么才能修复它们。谢谢
发布于 2015-01-15 00:18:47
我刚刚在所有主流浏览器中使用此jquery代码测试了您的代码,所有的代码都正常工作,它们关闭了连接并显示了结果:
$.ajax({
url: "index.php"
}).done(function(data) {
$('#remote').html(data);
});https://stackoverflow.com/questions/27835921
复制相似问题