title: javascript set header Access-Control-Allow-Origin
body: <p>I'm testing JS with POST. But I didn't get success with that.</p>
  <p>Using the code:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;div&gt;
  testing js...
  &lt;/div&gt;
  
  &lt;script&gt;
  function upload() {
      var method = &quot;POST&quot;;
      var url = &quot;http://127.0.0.1:9000/push&quot;;
  
      var xhr = new XMLHttpRequest();
  
      xhr.open(method, url);
  
      xhr.setRequestHeader(&quot;Content-Type&quot;, &quot;text/plain;charset=UTF-8&quot;);
      xhr.setRequestHeader(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);
      
      var text = {&quot;command&quot;:&quot;PUSH&quot;};
      xhr.send(text);
  
  }         
  upload();
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>I'm getting the following error:</p>
  <p><img src="https://i.stack.imgur.com/iRmhy.jpg" alt="enter image description here" /></p>
  <p>The weird is that the request header is not being set correctly through the line:</p>
  <pre><code>xhr.setRequestHeader(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);
  </code></pre>
  <p>The request header is like this:</p>
  <p><img src="https://i.stack.imgur.com/7DUeI.jpg" alt="enter image description here" /></p>