title: POST AJAX request denied - CORS?
body: <p>I have setup CORS on my node.js server on port 5000 as follows: </p>
  
  <pre><code>var app = express();
  
  app.use(cors()); //normal CORS
  app.options('*', cors()); //preflight 
  
  app.post('/connect', function(req, res) { 
      console.log("Connection request received !")
  });
  
  var port = 5000;
  app.listen(port, function () {
      console.log('Listening on port '+port);
  });
  </code></pre>
  
  <p>I am now trying to send AJAX POST requests using JQuery like so, in a static web page open from my hard disk :</p>
  
  <pre><code>var xhr = $.post({
              url: 'http://localhost:5000/connect',
              complete: function() {
                  console.log("done !")
              },
              crossDomain: true
          });
  
  xhr.fail(function(xhr, status, error){
      alert(error)
  })
  </code></pre>
  
  <p>The <code>complete</code> function is never called, and the only alert I get is an alert from the XHR <code>fail</code> handler, containing the following error :</p>
  
  <pre><code>NS_ERROR_DOM_BAD_URI: Access to restricted URI denied
  </code></pre>
  
  <p>I think CORS is well-configured, <strong>what am I missing ?</strong></p>
  
  <hr>
  
  <p><em>EDIT</em> : for those in my case, the best solution I could find was to send the page from the server :</p>
  
  <pre><code>app.use(express.static('web'))
  
  app.get("/", function(req, res) {
      res.sendFile(__dirname + '/web/HTML/index.html');
  });
  </code></pre>