I need to send some data to a Node server which is not serving the javascript. I run the server, but never see OPTIONS sent and Chrome is rejecting my ajax for being from a different domain.]
My server:
var http = require('http');
var router = require('router');
var routing = router();
var server = http.createServer(routing);
routing.options('*', function(request, response){
console.log("OPTIONS BEING SENT");
var origin = (request.headers.origin || "*");
response.writeHead("204",
"No Content",
{ "access-control-allow-origin": origin,
"access-control-allow-methods": "GET, POST, PUT, DELETE, OPTIONS",
"access-control-allow-headers": "content-type, accept",
"access-control-max-age": 10,
"content-length": 0
});
response.end();
});
server.listen(7738);
my js sends is jqxhr = $.get('localhost:7738/post/trackEvent/' + eventName);
but I never see OPTIONS BEING SENT. If I use another tool to hit the server with an OPTIONS request, it works as expected.
UPDATE:
Hitting the server with an OPTIONS request to http://localhost:7738/post/trackEvent/MoneyInTheBank
returns this:
HTTP/1.1 204 No Content
Content-Length: 0
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS
Access-Control-Allow-Headers: Content-Type, Accept
Access-Control-Max-Age: 10
Connection: close