0

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

maolddv
  • 97
  • 1
  • 2
  • 14

1 Answers1

0

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);
});
Marek
  • 7,337
  • 1
  • 22
  • 33