Reputation: 13907
ETA: Here's the JSFiddle, check your console: http://jsfiddle.net/GZNwK/1/
So I'm just trying to load a subreddit from the IMGUR API:
$.getJSON('http://imgur.com/r/cats.json?callback=?',function(data){
console.log(data)
})
But I end up with this error:
Not exactly sure why this is. I can load the Flickr API and the Instagram API in .jsom format, the syntax appears to be exactly the same. Why is the IMGUR API giving me an error? Also, if I remove ?callback=? then it it doesn't use JSONP and the cross-domain request fails.
Upvotes: 0
Views: 705
Reputation: 126042
Because this is not a resource that supports JSONP requests. I don't know a whole lot about IMGUR, but it looks like they do have an API you can use: http://api.imgur.com/
Another solution would be to use YQL:
$.ajax({
url: 'http://query.yahooapis.com/v1/public/yql',
data: {
q: 'select * from json where url="http://imgur.com/r/cats.json"',
format: 'json'
},
type: 'get',
dataType: 'jsonp'
}).success(function (data) {
/* results are in data.query.results.json.gallery */
alert(data.query.results.json.gallery[0].title);
});
Example: http://jsfiddle.net/sNSEA/
Although I would strongly recommend doing this the "right" way through the API if possible (a quick glance didn't yield anything).
Upvotes: 3