javascript - getJSON fails when i try to load user JSON -


this question has answer here:

i have made chrome extension facebook, private liking. want is, whenever posted post, , person clicked private button, has been included me. on click of private button, want json data of poster posted post. tried json of own profile, not return anything. below code !

var btn = "<button class=\"nadddim\" >get json</button>";  var t = document.getelementsbyclassname("_sg1 _3qd4");  t[0].insertadjacenthtml('beforebegin', btn);        document.getelementsbyclassname('nadddim')[0].addeventlistener('click',function(){    var fbjson;    $.getjson( "https://www.facebook.com/profile.php?id=100004774025067", function( data ) {    fbjson = data;  });    console.log(fbjson);  });

basically need user id , post, example john posted something, whenever privately liked post, want json of john extract id value ! thats need

you need use method .done() return data since getjson call asynchronous this:

$.getjson( "https://www.facebook.com/profile.php?id=100004774025067" ).         .done(function( data ) {             fbjson = data;         })         .fail(function() {             console.log( "error" );         }) 

also, might want check if there's errors using fail() , see http://api.jquery.com/jquery.getjson/. view content of error examine jqxhr object (jquery xmlhttprequest) instance this:

        .fail(function(jqxhr){             console.log( "error" );             console.log(jqxhr.responsetext);          }) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -