GetJSON API from jQuery

I am trying to download cover art from the Facebook API using jQuery and Json. Getting an error.

$(document).ready(function () {
        $("button").click(function () {
            $.getJSON("https://graph.facebook.com/cocacola")
       $("#fbapi-results").attr("src", json.cover.source).appendTo("#fbapi-results");
        });
   });

See the attached script.

http://jsfiddle.net/sowljur/u8YLP/1/

UPDATE: json file structure

https://graph.facebook.com/cocacola

Trying to get the source code download when a button is clicked. Thank!

+3
source share
3 answers

$. getJSON is an asynchronous function and requires a callback http://api.jquery.com/jquery.getjson/

$(document).ready(function () {
        $("button").click(function () {
            $.getJSON("https://graph.facebook.com/cocacola", function (json) {
                console.log(json.cover.source);
       $("#fbapi-results").attr("src", json.cover.source).appendTo("#fbapi-results");
            })
        });
   });

Fiddle http://jsfiddle.net/sajith/724Vc/

+4
source

You can try the following:

  $.getJSON('"https://graph.facebook.com/cocacola"jsoncall=?',
           function(data) {
              $.each(data.posts, function(key, val) {
                       // Dynamic  list creation
                      $('#Mylist').append('<li><a id="'+ val.Name +
                      '" href="' + val.proImage + '"><img  src="'
                       + val.proImage + '"   alt="'+ val.Project +
                      ' " title="" ></img></a></li>').trigger('create');

               });
     });
+1
source

. div getJSON .

<button class="press-button">Get Facebook Coca Cola Cover</button>
<img id="fbapi-results" class="results"/>

JavaScript:

$(document).ready(function () {
    $("button").click(function () {
        $.getJSON("https://graph.facebook.com/cocacola",function(root){
   $("#fbapi-results").attr("src", root.cover.source).appendTo("#fbapi-results");
    });
 });
});

http://jsfiddle.net/u8YLP/3/

+1