title: getting a server 500 error during a CORs response
body: <p>I am trying to send a JSON buffer from a Chrome extension but am getting an internal 500 error. Here is the code that sends the buffer. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var xhr = new XMLHttpRequest();
  xhr.onerror = function(req,textStatus,errorThrown) {
      console.log(textStatus);
      alert('on-error')};
  
      xhr.open('POST', url, true);
      xhr.setRequestHeader("Content-type", 'application/json');
      xhr.setRequestHeader("X-Requested-With",'XMLHttpRequest');
      xhr.setRequestHeader("Access-Control-Allow-Origin", '*');
   
      xhr.onload = function () {   //response will go here
          if(xhr.status == 500) {
              alert("server error 500");
          }</code></pre>
  </div>
  </div>
  </p>
  
  <p>On the Apache Linux server side, I send back a response with </p>
  
  <pre><code>enter code here
         $this-&gt;output
              -&gt;set_content_type('application/json')
              -&gt;set_header("Access-Control-Allow-Origin", "*")
              -&gt;set_output(json_encode($table));
  </code></pre>
  
  <p>I have been stuck on this problem for over a month and really need some ideas on what I am doing wrong. I have debuggers on both machines. I see that the buffer is going out correctly and I can see it is being received correctly. I think I am setting the response header correctly but I always get a 500 error. BTW, it works fine with a WAMP running on my localhost. </p>
  
  <p>This is from the apache error_log: [Fri Oct 26 18:22:07.162178 2018] [proxy_fcgi:error] [pid 2001:tid 139930806171392] [client 69.124.178.164:57141] malformed header from script 'index.php': Bad header: {"0":["{choose}","IOS","Mac","
  [Fri Oct 26 18:22:07.163669 2018] [proxy_fcgi:error] [pid 2001:tid 139930806171392] [client 69.124.178.164:57141] AH01070: Error parsing script headers
  [Fri Oct 26 18:22:07.163679 2018] [proxy_fcgi:error] [pid 2001:tid 139930806171392] (22)Invalid argument: [client 69.124.178.164:57141] AH01075: Error dispatching request to : 
  [Fri Oct 26 18:22:33.796554 2018] [proxy_fcgi:error] [pid 2001:tid 139930797778688] [client 69.124.178.164:57179] malformed header from script 'index.php': Bad header: {"0":["{choose}","IOS","Mac","
  [Fri Oct 26 18:22:33.796627 2018] [proxy_fcgi:error] [pid 2001:tid 139930797778688] [client 69.124.178.164:57179] AH01070: Error parsing script headers
  [Fri Oct 26 18:22:33.796633 2018] [proxy_fcgi:error] [pid 2001:tid 139930797778688] (22)Invalid argument: [client 69.124.178.164:57179] AH01075: Error dispatching request to : </p>
  
  <p>The line that says malformed header is actually my payload from the server to the Extension. Is is not a header, it is the payload. </p>