title: Error in making a request to local host 8080 from a local file
body: <p>I have created an ajax request to localhost whenever a button on my page is pressed. And I have created a server using nodejs listening on port 8080. But when I press the button, following error is given in chrome developer tools terminal:</p>
  
  <pre><code>Access to XMLHttpRequest at 'http://localhost:8080/' from origin 'null' 
  has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header 
  is present on the requested resource.
  </code></pre>
  
  <p>I am trying to learn how to communicate with the server. I am very new to this so sorry if my questions sounds ridiculous.</p>
  
  <p>Code to make the http request:</p>
  
  <pre><code>function loadDoc() {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
      if (this.readyState == 4 &amp;&amp; this.status == 200) {
        document.getElementById("print_here").innerHTML = this.responseText;
      }
    };
    xhttp.open("POST", "http://localhost:8080", true);
    xhttp.send("first_name");
  }
  </code></pre>
  
  <p>Server Node js code listening on port 8080:</p>
  
  <pre><code>var http = require('http');
  //create a server object:
  http.createServer(function (req, res) {
    res.write('Last_name'); //write a response to the client
    res.end(); //end the response
  }).listen(8080); //the server object listens on port 8080
  </code></pre>
  
  <p>What dose the error message mentioned above mean? (The file which is making the http request is in a folder on my desktop. The nodejs file that creates a server to listen on port 8080 is also in the same folder.)</p>