Consider an AJAX call that writes to a div:
recent_req=$.post('result.php', { d: data }, function(returnData) {
$('#content').html(returnData);
});
The PHP script at result.php
performs some functions that take time, about 5-20 seconds per step. I am using PHP's flush()
function to get the info to the browser as soon as each step starts and ends, but how can I get the Javascript to write the data to the #content
div as it comes in?
Thanks.
EDIT:
To clarify: Assume result.php
looks like the following and due to constraints cannot be practically refactored:
<?php
echo "Starting...<br />";
flush();
longOperation();
echo "Done with first long operation.<br />";
flush();
anotherLongOperation();
echo "Done with another long operation.<br />";
flush();
?>
How might the AJAX be structured to call result.php
such that the echo statements are appended to the #content
div as they come in? Any solution with / without jQuery is welcome. Thanks!