title: Why XmlHttpRequest readyState = 2 on 200 HTTP response code
body: <p>So I'm using plain javascript (no jquery), to send a file to the server.  Server script PHP returns status code 200 at the end, but instead javascript is getting readyState == 2.</p>
  
  <p>The PHP code sends back status code 200:</p>
  
  <pre><code>header('X-PHP-Response-Code: 200', true, 200);
  exit;
  </code></pre>
  
  <p>The javascript is doing:</p>
  
  <pre><code>request.onreadystatechange = function() {
          if (request.readyState == 4) {
              var message;
              switch(request.status) {
                  case '200':
                       message = "Data uploaded successfully.";
                  break;
  
                  case '406':
                      message = "Incorrect file format.  Please try again.";
                  break;
  
                  case '410':
                      message = "Unexpected error.  Please contact support.";
                  break;
  
                  default:
                  break;
              }
              status_message_container.innerHTML = message;
              submit_button.disabled = false;
          }
          else {
              alert( "Unexpected error:  " + this.statusText + ".\nPlease try again");
          }
      };
  
      request.send(formData);
  </code></pre>
  
  <p>Even know the HTTP 200 status code comes back correctly (I get 'OK') on frontend.  The JS script is seeing <code>readyState==2</code> (i.e. else block always hit)</p>
  
  <p>My understanding is that a server status code of 200 should give <code>readyState == 4</code>??</p>