title: xmlhttprequest not firing response event handler for ready state 3 when using flush from php
body: <p>I am sending a request a remote server from google chrom extension using xmlhttprequest</p>
  
  <p>I have set permissions in the manifest.json to access remote hosts</p>
  
  <p>Basically it is working fine as expected. what i had expected is readystate 4 it is fired when the response has completed.</p>
  
  <p>Since it is a 8 to 10 second process in the server side i use echo from the server side to the client for status update.</p>
  
  <p>so i use readyState==3 condition to show server response</p>
  
  <p>but when i tested readystate 1 and 4 are firing the event handler and not 2 and 3</p>
  
  <p>here is the code i use</p>
  
  <pre><code>var wini = window.open('','');
  var sta='';
  var jax = new XMLHttpRequest();
  jax.onreadystatechange = function() {
      sta = sta + jax.readyState + ', '
      wini.document.write(sta+'&lt;br&gt;');
  
  }
  jax.open("POST","http://sitename.com/subscript/?save=save&amp;tstamp="+Math.random());
  jax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  //jax.setRequestHeader("Connection: close");
  jax.send("somedata=" + encodeURIComponent(window.somedata));
  </code></pre>
  
  <p><em><strong>using connection close. a different result. except readystate 1 no others were fired</em></strong></p>
  
  <p>So, readystates 1 and 4 are working fine but not 2 and 3. what is most needed is 3.</p>
  
  <p>what is actually happens with the code runs is:</p>
  
  <p>1, is printed in the popup window and then 8 to 9 secs pass and when ready state is 4</p>
  
  <p>1,2</p>
  
  <p>1,2,3</p>
  
  <p>1,2,3,4 </p>
  
  <p>the above three lines are printed in one shot. so i assume only by readystate 4 i am getting all the response from the server and not while readystate is 3.</p>
  
  <p>I have used readystate 3 in other web applications which is of same origin and it worked and is still working.</p>
  
  <p>for this xhr i don't know what i am missing.</p>
  
  <p>How to make use of  readystate 3 here?</p>