I know there is no shortage of CORS
questions on SO but none could help me in this circumstances:
I'd like to get JSON data from localhost backend using this jQuery snippet:
var SERVER_URL = "http://127.0.0.1:8080";
$.getJSON(SERVER_URL,function(result){
console.log("result is", result);
$.each(result, function(i, field){
$("div").append(field + " ");
});
});
The snippet is loaded to index.html
which is run on http://localhost:3000/index.html
using this simple node static-file server:
var connect = require('connect');
var serveStatic = require('serve-static');
connect().use(serveStatic(__dirname)).listen(3000, function(){
console.log('Server running on 3000...');
});
But in Chrome console I get:
Failed to load http://127.0.0.1:8080/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
I had the same issue in Firefox.
How can I fix this?