I'm on site.com trying to grab some json data from my node.js server serving on port 8080.
I get this Error message:
XMLHttpRequest cannot load http://site.com:8080/json/1. Origin http://site.com is not allowed by Access-Control-Allow-Origin.
my code:
$.get('http://site.com:8080/1/', {}, function (Data) {
console.log(Data);
}, "json");
But it is the same domain though! :(
Also consider my backbone.js model:
model = Backbone.Model.extend({
url: function() {
return 'http://site.com:8080/' + this.id
}
});
Is there any way to resolve this other than using jsonp?
Thanks.
If you're making the call to the same domain, why do you have the absolute path in your $.get
request?
Try this:
$.get('/1/', {}, function (Data) {
console.log(Data);
}, "json");
model = Backbone.Model.extend({
url: function() {
return '/' + this.id
}
});
If you are truly making the call on the same domain, then the above code should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With