<p>With this code I can show an animated gif while the server script is running:</p>

<pre><code>function calculateTotals() {
    $('#results').load('getResults.php', null, showStatusFinished);
    showLoadStatus();
}

function showLoadStatus() {
    $('#status').html('');
}


function showStatusFinished() {
    $('#status').html('Finished.');
}
</code></pre>

<p>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.</p>

<p>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?</p>

[{'answer_id': 71648, 'author': 'squadette', 'author_id': 7754, 'author_profile': 'https://Stackoverflow.com/users/7754', 'pm_score': 0, 'selected': False, 'text': '<p>Your server-side script should somehow keep its progress somewhere on server (file, field in database, memcached, etc.).  </p>\n\n<p>You should have AJAX function returning current progress.   Poll this function once a second and render result accordingly.   </p>\n'}, {'answer_id': 71667, 'author': 'Andrew Wilkinson', 'author_id': 2990, 'author_profile': 'https://Stackoverflow.com/users/2990', 'pm_score': 0, 'selected': False, 'text': "<p>Without knowing how your server side code works it's hard to say. However, there are three stages to the process. Firstly you need to call a job creation script. This returns an id number and sets the server working. Next, every second or so, you need to call a status script which returns an status message that you want to display. That status script also needs to return a value indicating whether the job has finished or not. When the status script says the job has finished you stop polling.</p>\n\n<p>How you get this status script is to know the status of the job depends greatly on how server is set up, but probably involves writing the message to a database table at various points during the job. The status script then reads this message from the database.</p>\n"}, {'answer_id': 71727, 'author': 'Dan F', 'author_id': 11569, 'author_profile': 'https://Stackoverflow.com/users/11569', 'pm_score': 1, 'selected': False, 'text': '<p>I\'m not down with the specifics for jQuery, but a general answer that doesn\'t involve polling wold be: Use a variation of the <a href="http://cometdaily.com/2007/11/05/the-forever-frame-technique/" rel="nofollow noreferrer">forever frame</a> technique. Basically, create a hidden iframe, and set the src of it to be \'getresults.php\'. Inside getresults you "stream" back script blocks, which are calls to a javascrpt function in the parent document that actually updates the progress. Here\'s <a href="http://www.codeproject.com/KB/aspnet/ASPNETAJAXPageLoader.aspx" rel="nofollow noreferrer">an example</a> that shows the basic idea behind a forever frame. (I wouldn\'t recommend using his actual JS or HTML though, it\'s reasonably average)</p>\n'}, {'answer_id': 165872, 'author': 'matdumsa', 'author_id': 1775, 'author_profile': 'https://Stackoverflow.com/users/1775', 'pm_score': 3, 'selected': True, 'text': '<p>After reading your comments to Andrew\'s answer.</p>\n\n<p>You would read the status like this:</p>\n\n<pre><code>function getStatus() {\n    $.getJSON("/status.php",{"session":0, "requestID":12345}, \n    function(data) { //data is the returned JSON object from the server {name:"value"}\n          setStatus(data.status);\n          window.setTimeout("getStatus()",intervalInMS)\n    });\n}\n</code></pre>\n\n<p>Using this method you can open several simultaneous XHR request on the server.</p>\n\n<p>all your status.php as to output is :</p>\n\n<pre><code>{"status":"We are done row 1040/45983459"}\n</code></pre>\n\n<p>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..)</p>\n\n<p>For more information on $.getJSON see <a href="http://docs.jquery.com/Ajax/jQuery.getJSON" rel="nofollow noreferrer">http://docs.jquery.com/Ajax/jQuery.getJSON</a></p>\n'}]
['https://Stackoverflow.com/questions/71590', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4639/']