Jiew Meng
Jiew Meng

Reputation: 88207

nothing (expecting JSON) returned from server?

i am trying to experiment with the tumblr api. i tried

$(function() {
  $.getJSON("http://jiewmeng.tumblr.com/api/read/json", function(data) {
    $("#postsContainer").append(data);
  });
});

but got a 200 OK with empty response in firebug. when i navigate to http://jiewmeng.tumblr.com/api/read/json, i see the data. so i shld be getting something rather than a empty response?

Upvotes: 0

Views: 175

Answers (1)

Nick Craver
Nick Craver

Reputation: 630429

You have 2 issues, here, for cross-domain requests you need JSONP, by sticking callback=? in the URL, and you need to access some property, like this: data.tumblelog.title. Here's an example:

$(function() {
  $.getJSON("http://jiewmeng.tumblr.com/api/read/json?callback=?", function(data) {
    $("#postsContainer").text(data.tumblelog.title);
  });
});​

You can view a quick demo here, to see what data is available the API can be found here, or view it in your console...or just visit the URL yourself and paste the result into a markup site, like jsbeautifier.org to make it more readable.

Upvotes: 4

Related Questions