javascript - getJSON fails when i try to load user JSON -
this question has answer here:
- how return response asynchronous call? 21 answers
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
Post a Comment