How can I use the $.ajax() function to display output in real time. Right now I am using it in this context:
$.ajax({
type: 'get',
url: 'process.php',
data: 'foo=boo',
success: function(output) {
$('div#results').html(output);
}
});
The above displays the output recived from the PHP script only AFTER the script has fully executed. So if in the php script you had the following:
echo 'Hello for the first time';
// some code
echo 'Hello again';
// some code
echo 'Are you still here?';
The output would be all those echos all at one. Instead, is there any way I can update the output received from the PHP script one after another as the requests are being fulfilled by PHP in real time?
I know how to update things in real time when working entirely in the realm of JavaScript, for example: checking if the input being typed is at least 10 characters long using the keyup() event as a trigger to check after every entered key and displaying a message to enter something more which disappears as soon as the 10th character is typed.
But how to do something like this when the output is coming from a PHP file? is it even possible?
Reason why I need to do this is because I would like to have a status screen that shows how much progress has been made and what part of a task the script is currently handling, like how desktop apps have.