[英]CORS Error : No 'Access-Control-Allow-Origin' header is present
I am getting this error but everything required for CORS is defined on Node.js server. 我收到此错误,但CORS所需的所有内容均在Node.js服务器上定义。
I am using localhost:3000 我正在使用localhost:3000
Frontend Code : 前端代码:
jQuery.ajax({
type : "GET",
url : "http://testing.com/iverse.json",
success : function(result) {
console.log("here is the result===",result);
}
});
Node.js Code for headers 标头的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();
});
Please let me know where is the error ? 请让我知道错误在哪里?
The 'Access-Control-Allow-Origin' header has to be provided from the requested resource. 必须从请求的资源中提供“ Access-Control-Allow-Origin”标头。
Take a look at this stackoverflow question and the accepted answer for more details. 请查看此stackoverflow问题和可接受的答案以获取更多详细信息。
just use this cors modlue 只需使用此cors modlue
var cors = require('cors');
app.use(cors());
it help to you 它对你有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.