Reputation: 3047
I am getting this error but everything required for CORS is defined on Node.js server.
I am using 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
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 ?
Upvotes: 0
Views: 971
Reputation: 471
The 'Access-Control-Allow-Origin' header has to be provided from the requested resource.
Take a look at this stackoverflow question and the accepted answer for more details.
Upvotes: 1
Reputation: 910
just use this cors modlue
var cors = require('cors');
app.use(cors());
it help to you
Upvotes: 0