title: Javascript - No 'Access-Control-Allow-Origin' header is present on the requested resource
body: <p>I need to send data through <code>XmlHttpRequest</code> from JavaScript to Python server. Because I'm using localhost, I need to use <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS" rel="noreferrer">CORS</a>. I'm using the Flask framework and its module <code>flask_cors</code>.</p>
  
  <p>As JavaScript I have this:</p>
  
  <pre><code>    var xmlhttp;
      if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp = new XMLHttpRequest();
      }
      else {// code for IE6, IE5
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.open("POST", "http://localhost:5000/signin", true);
      var params = "email=" + email + "&amp;password=" + password;
  
  
      xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
          if(xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) {
              alert(xmlhttp.responseText);
          }
      }
      xmlhttp.send(params);
  </code></pre>
  
  <p>and Python code:</p>
  
  <pre><code>@app.route('/signin', methods=['POST'])
  @cross_origin()
  def sign_in():
      email = cgi.escape(request.values["email"])
      password = cgi.escape(request.values["password"])
  </code></pre>
  
  <p>But when I execute it I get this message:</p>
  
  <blockquote>
    <p>XMLHttpRequest cannot load localhost:5000/signin. No
    'Access-Control-Allow-Origin' header is present on the requested
    resource. Origin 'null' is therefore not allowed access.</p>
  </blockquote>
  
  <p>How should I fix it? I know that I need to use some "Access-Control-Allow-Origin" header but I don't know how to implement it in this code. By the way I need to use pure JavaScript.</p>