0

I have this simple JQUERY code:

$(document).ready(function () {
     $(document).on('click', 'button', function(){
         $.post('post.php',
         {
             test: 'yes'
         },
         function(data, textStatus)
         {
            alert(data);
         });
      }); 
});

And this post.php page:

<?php

/* do some stuff that takes time */
echo '1';

?>

So i submit a POST request to PHP page using JQUERY and want to alert the response which is 1 in the above example. The problem is that the script takes sometime to fully execute which in return slows down the response.

This is just a very simplified example. Is there a way to get the response before the full loading of the PHP script? I tried to echo before the rest of the script but it doesn't matter as the response won't be sent before the script completes all the tasks.

Michael Samuel
  • 3,820
  • 12
  • 45
  • 85
  • 1
    Possible duplicate: http://stackoverflow.com/questions/3133209/how-to-flush-output-after-each-echo-call – hindmost Nov 08 '14 at 15:38

1 Answers1

0

You can try flushing the buffer.

yelly
  • 161
  • 3