title: Cors Policity Error: It does not have HTTP ok status
body: <p>I have created my own restful application in <code>PHP</code> that exposes APIs to <code>javascript</code> application. Everything works smoothly except when I insert <code>http_response_code</code> in the response header.</p>
  <p>Below is the function I use to print the data in json format. I set the <code>http_response_code()</code> based on the error code I need to use (200, 404, 400, 401 etc).</p>
  <pre><code>&lt;?php
  
  public function handle($code = 200, $data = array())
  {
      $message = json_encode(
          array(
              &quot;code&quot; =&gt; $code,
              &quot;data&quot; =&gt; $data
          ), JSON_PRETTY_PRINT
      );
          
      http_response_code($code);
  
      header(&quot;Access-Control-Allow-Origin: *&quot;);
      header(&quot;Access-Control-Allow-Headers: *&quot;);
      header(&quot;Access-Control-Allow-Methods: GET, POST, PUT, DELETE&quot;);
      header('Content-type: text/javascript; charset=utf-8'); 
          
      print_r($message);
      exit;
  }
  </code></pre>
  <p>Frontend side, I make simple <code>Ajax</code> calls with <code>jQuery</code>. I don't think it needs any explanation but I put it for completeness.</p>
  <pre><code>$.ajax({
      url: url,
      method: method,
      cache: false,
      headers: headers,
      data: data,
      crossDomain: true, 
      success: function(data){
          console.log(data)
      },
      error: function (xhr, ajaxOptions, thrownError) {
          console.log((xhr.responseJSON)
      }
  });
  </code></pre>
  <p>The problem is this. If in the <code>PHP</code> script I comment the line <code>http_response_code($code);</code> Everything works smoothly, but I always receive as status code 200.</p>
  <p>If I try to change the status code, be it 200 or any other code, the client responds with the following error:</p>
  <p><code>Access to XMLHttpRequest at 'MY API URL CENSORED' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.</code></p>
  <p>As you can see both <code>php</code> and <code>js</code> side I have enabled cross domain and enabled all cross-origin. I don't really understand why it gives me this error, only if I add this line <code>http_response_code($code)</code>.</p>
  <p>Am I doing something wrong? Can changing the status code create any kind of problem with <code>cors</code> policies?</p>