我正在尝试向此 URL发出 AJAX GET 请求并处理 JSON 响应。如果您直接访问该 URL,它就可以工作。我也尝试通过Hurl It运行它,它也可以工作。
我不知道为什么我不能通过 jQuery 向它发出JSON
/JSONP
请求。
我最初尝试做出 JSON 响应,但得到:
XMLHttpRequest cannot load http://hndroidapi.appspot.com/news/format/json/page/. Origin http://hackernews.dev is not allowed by Access-Control-Allow-Origin.
因此,我尝试了 JSONP,并得到
Uncaught SyntaxError: Unexpected token : hndroidapi.appspot.com:1
第 1 行是整个 JSON 响应,在一行中,但没有包含在回调中。因此,这个 API 似乎不支持 JSONP。
因此,我能做些什么来解决这个问题吗?不幸的是,我有点难过,似乎没有办法解决这个问题。
我的代码如下:
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);
});
非常感谢任何帮助!