I’m trying to make an AJAX GET request to this URL and process the JSON response. If you visit that URL directly, it works. I’ve also tried running it through Hurl It, and it works too.
I’m there for at a loss as to why I can’t make a JSON / JSONP request to it through jQuery.
I initially tried to make a JSON response but get:
XMLHttpRequest cannot load http://hndroidapi.appspot.com/news/format/json/page/. Origin http://hackernews.dev is not allowed by Access-Control-Allow-Origin.
So therefore I took an attempt at JSONP, and get
Uncaught SyntaxError: Unexpected token : hndroidapi.appspot.com:1
Line 1 is the entire JSON response, in one line, but not wrapped in a callback. Hence, it seems this API does not support JSONP.
Hence, is there anything I can do to solve this? I’m a little stumped unfortunately, it doesn’t seem like there’s a way round this.
My code is as follows:
var ajaxReq = $.ajax({
url: "http://hndroidapi.appspot.com/news/format/json/page/",
dataType: "jsonp"
});
ajaxReq.done(function(d) {
console.log("DONE", d);
});
ajaxReq.error(function(d) {
console.log("ERROR", d);
});
Any help much appreciated!
The api definitely does not support JSONP (unless i’m missing something, not too familiar with python) : https://github.com/glebpopov/Hacker-News-Droid-API/blob/master/Formatter.py your only option at this point is to either use YQL or a server-side proxy