【发布时间】:2016-11-06 21:00:22
【问题描述】:
我收到此错误,但 CORS 所需的一切都在 Node.js 服务器上定义。
我正在使用 localhost:3000
前端代码:
jQuery.ajax({
type : "GET",
url : "http://testing.com/iverse.json",
success : function(result) {
console.log("here is the result===",result);
}
});
标头的 Node.js 代码
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, ajax, access-key');
res.setHeader('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS, HEAD');
res.setHeader('Access-Control-Allow-Origin', "*");
next();
});
请告诉我错误在哪里?
【问题讨论】:
-
您在哪一侧设置标题?为 JS 服务的那个还是被请求的那个?
-
我在 localhost node.js 服务器上设置标题
-
必须在请求的资源上提供 Access-Control-Allow-* 标头。