[英]jQuery not sending a custom headers CORS request to node.js server, or server not receiving?
[英]CORS with Node.js and jQuery
我需要將一些數據發送到不提供javascript的Node服務器。 我運行服務器,但從未看到OPTIONS已發送,而Chrome拒絕我的ajax來自其他域名。]
我的服務器:
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);
我的js發送的是jqxhr = $.get('localhost:7738/post/trackEvent/' + eventName);
但我從來沒有看到過選擇。 如果我使用其他工具使用OPTIONS請求命中服務器,它將按預期工作。
更新:
使用OPTIONS請求命中服務器到http://localhost:7738/post/trackEvent/MoneyInTheBank
返回:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.