title: Conveying server-side PHP script progress to client side javascript
body: <p>Seems that something has changed in Ajax-land; a process that worked well for years to let the user know the server was actually chewing through its work has stopped working.</p>
  <p>I've distilled it down as best I can to the following:</p>
  <p>Client-side:</p>
  <pre><code>function start () {
          var jsonResponse = '', lastResponseLen = false;
  
          $.ajax({
              url: getAjaxUrl(),
              method: 'POST',
              data: {
                  REQ_TYPE: 'Misc_Action',
                  SUB_TYPE: 'Misc_TestComms'
              },
              xhrFields: {
                  onprogress: function(e) {
                      var thisResponse, response = e.currentTarget.response;
                      if(lastResponseLen === false) {
                          thisResponse = response;
                          lastResponseLen = response.length;
                      } else {
                          thisResponse = response.substring(lastResponseLen);
                          lastResponseLen = response.length;
                      }
  
                      jsonResponse = JSON.parse(thisResponse);
  
                      document.getElementById('messages').innerHTML = 'Processed '+jsonResponse.count+' of '+jsonResponse.total;
                  }
              },
              success: function(text) {
                  console.log('done!');
                  document.getElementById('messages').innerHTML = 'Process completed successfully';
              }
          });
      }
  </code></pre>
  <p>(note that the url is correctly formed)</p>
  <p>Server-side:</p>
  <pre><code>function Misc_TestComms () {
      $runs = 25;
      $i = 0;
      echo json_encode(array('progress' =&gt; 0, 'count' =&gt; $i);
      flush();
      ob_flush();
  
      while ($i &lt; $runs) {
          $i++;
          echo json_encode(array('progress' =&gt; (($i/$runs)*100), 'count' =&gt; $i);
          flush();
          ob_flush();
          sleep(1);
      }
  }
  </code></pre>
  <p>The client-side receives no <code>progress</code> messages until the script has completed, at which point both the <code>onprogress</code> and <code>success</code> sections are triggered.</p>
  <p>Suggestions?</p>