With this code I can show an animated gif while the server script is running:
function calculateTotals() { $('#results').load('getResults.php', null, showStatusFinished); showLoadStatus(); } function showLoadStatus() { $('#status').html(''); } function showStatusFinished() { $('#status').html('Finished.'); }
However, I would like to display a status of how far along the script is, e.g. ‘Processing line 342 of 20000…’ and have it count up until it is finished.
How can I do that? I can make a server-script which constantly contains the updated information but where do I put the command to read this, say, every second?
After reading your comments to Andrew’s answer.
You would read the status like this:
Using this method you can open several simultaneous XHR request on the server.
all your status.php as to output is :
You can however output as many information you want in the response and to process it accordingly (feeding a progress bar for example or performing an animation..)
For more information on $.getJSON see http://docs.jquery.com/Ajax/jQuery.getJSON