title: Can't get 401 response body
body: <p>I managed to get JSON content using <code>jQuery.ajax()</code>. Currently, it fetches the content from another host containing a single index.php file returning a 401 response with the following body: <code>{'status':401}</code>.</p>
  
  <p>This is the JS:</p>
  
  <pre><code>$(document).ready(function() {
      $.ajax({
          url: 'http://restapi',
          type: 'GET',
          dataType: 'json',
          success: function() { document.write('works'); },
          error: function(xhr) { document.write('failed, status:' + xhr.status); },
          beforeSend: setHeader
      });
  });
  
  function setHeader(xhr) {
      xhr.setRequestHeader('Authorization', 'Bearer 12345');
  }
  </code></pre>
  
  <p>And the PHP:</p>
  
  <pre><code>&lt;?php
  
  header("Access-Control-Allow-Origin: *");
  header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
  header('Access-Control-Allow-Credentials: true');
  header("Access-Control-Allow-Headers: X-Requested-With, Authorization");
  
  header("HTTP/1.1 401 Unauthorized");
  
  echo json_encode(['status' =&gt; 401]);
  
  exit;
  </code></pre>
  
  <p>If I remove the header, <code>xhr.setRequestHeader('Authorization', 'Bearer 12345');</code>, everything works fine (the response has a json body and <code>xhr.status</code> returns <code>401</code>). But with the Authorization header the body returns nothing and <code>xhr.status</code> returns <code>0</code>.</p>
  
  <p>I need to send the auth token in that header.</p>