I know the problem with ajax and return variables, I was reading in stackoverflow about this, I know that I have to use a callback function, but in my case didn't work, of course something I'm making wrong
My code is this:
var id_user=get_id_user_login();//undefined??????????
function get_id_user_login(){
FB.api(
'/me',
{fields:'id'},
function(response){//callback
console.log(response.id);//OK
return response.id;
}
);
};
You can´t just return the value because it´s asynchronous. Try this:
function customFunction(id) {
console.log(id);
}
function get_id_user_login(){
FB.api(
'/me',
{fields:'id'},
function(response){
customFunction(response.id);
}
);
};
get_id_user_login();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With