title: React JS fetch as POST to cross-origin, PHP returns 200 but without body response
body: <p>I know similar questions have been asked, but nothing on here as worked. Thank you in advance!</p>
  
  <p>I'm using fetch from a react JavaScript app (located at <a href="http://localhost:3000" rel="nofollow noreferrer">http://localhost:3000</a>) to post data too, and get a response from a local PHP API (using XAMPP and located at <a href="http://local.api.mysite.com/user" rel="nofollow noreferrer">http://local.api.mysite.com/user</a>)</p>
  
  <p>Every-time I get a 200 status without any returned headers or body. If I go to the PHP URL in my browser it works just fine</p>
  
  <p>I've ensured cors is set in both js and php, set content types, turned off caching, and tried every suggested fix on here and Google.</p>
  
  <p>This is a last resort</p>
  
  <p>JS:</p>
  
  <pre class="lang-js prettyprint-override"><code>fetch('http://local.api.mysite.com/user', {
      method: 'POST',
      mode: 'cors',
      headers: {
          'Content-Type': 'application/json',
          'Cache-Control': 'no-cache'
      },
      body: JSON.stringify(data),
      }).then(console.log(response))
  
  </code></pre>
  
  <p>PHP:</p>
  
  <pre class="lang-php prettyprint-override"><code>// Allow from any origin
  if (isset($_SERVER['HTTP_ORIGIN'])) {
      header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
      header('Access-Control-Allow-Credentials: true');
      header("Cache-Control: no-cache");
  }
  // Access-Control headers are received during OPTIONS requests
  if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
      if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
          header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
      if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
          header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
      exit(0);
  }
  $output = json_encode(['status' =&gt; 'recieved']);
  header('Content-Length: '.strlen($output));
  header('Content-Type: application/json');
  echo $output;
  exit;
  
  </code></pre>
  
  <p>Previously I had limited my PHP headers to be more restrictive, but I found this code block and am using it to let anything pass for testing.</p>
  
  <p><strong>Solution</strong>
  Rikin's comment on his answer had me open dev tools, go to the network tab, and view the response directly. This showed a server error that was occurring and leading to the empty response with a 200 status</p>