max_
max_

Reputation: 24521

Trouble with getting JSON in JQuery

I am trying to view the data retrieved from this function in order to parse the json, but I can't view the 'data' within the function. Please can you tell me what I am doing wrong?

My code is here: http://jsfiddle.net/sbbc7/4/

$.getJSON("api.forrst.com/api/v2/user/posts?username=_max&callback=?", function(data) {
    #("forrst").append(data);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<div id="forrst">
    
</div>

Upvotes: -1

Views: 58

Answers (3)

artlung
artlung

Reputation: 33833

$.getJSON("http://api.forrst.com/api/v2/user/posts?username=_max&callback=?", function(data) {
    $.each(data.resp.posts, function(index, val){
        $("#forrst").append("<h2><a href='" + val.post_url + "'>" + val.title + "</a></h2>")
        $('#forrst').append(val.formatted_description);
        $('#forrst').append("<hr>");
    });
});

Upvotes: 0

Colin Brock
Colin Brock

Reputation: 21575

Well, for one,

#("forrst").append(data);

should be

$("#forrst").append(data);

And, as genesis-φ points out below, you need to specify what exactly you're appending to the div.

Upvotes: 1

genesis
genesis

Reputation: 50982

You have probably meant

$("#forrst").append(data);

instead of

#("forrst").append(data);

And you need to specify which key exactly you want to append. For example,

$("#forrst").append(data.resp.posts[0].id);

http://jsfiddle.net/sbbc7/10/

Upvotes: 1

Related Questions