I’m making webpage using facebook API.
I want to show user’s friends in webpage.
So I code like this
function showFriends(){
var result = getFriends();
for(var i=0; i<result.length; i++){
//show friends in webpage
}
}
function getFriends(){
FB.api( {
method: 'fql.query',
query: 'SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())'},
function(response) {
return response;
}
);
}
Problem is this : getFriends function need a little time, so for loop processes before getting response of getFriends. And I don’t want to locate for loop in getFriends function because getFriends function will be used in many other function.
So is there any solution to wait function’s response?
Pass the
showFriendsfunction as a callback.