I'm trying to fetch the feed of a news website. Thought I'd use google's feed API to convert the feedburner feed into json. The following url will return 10 posts from the feed, in json format. http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=http://feeds.feedburner.com/mathrubhumi
I used the following code to get the contents of above url
$.ajax({
type: "GET",
dataType: "jsonp",
url: "http://ajax.googleapis.com/ajax/services/feed/load",
data: {
"v": "1.0",
"num": "10",
"q": "http://feeds.feedburner.com/mathrubhumi"
},
success: function(result) {
//.....
}
});
but it's not working and I'm getting the following error
XMLHttpRequest cannot load http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=http%3A%2F%2Ffeeds.feedburner.com%2Fmathrubhumi. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
How do I fix this?
I believe this might likely be that Chrome does not support localhost
to go through the Access-Control-Allow-Origin
-- see Chrome issue
To have Chrome send Access-Control-Allow-Origin
in the header, just alias your localhost in your /etc/hosts file to some other domain, like:
127.0.0.1 localhost yourdomain.com
Then if you'd access your script using yourdomain.com
instead of localhost
, the call should succeed.
Thank you. I was experiencing this issue and switching to IE edge, caused me to see the underlying error in my server code which was being obscured by Chrome's denial of localhost.
Doesn't work for me either. Perhaps an update to Chrome blocked this "loophole"?
No help here either. My website is already set up this way, however I do have one big difference. I'm using a different port. I'm sure if it were the same port, it would work. HTTP vs. HTTPS are of course different ports, so that might cause some of you issues. Mine isn't HTTPS in particular, but I am trying to access something on the same domain but a different port other than 80.
What if the API is being accessed by a chrome extensions, what can be done