문제

placing a fb js sdk api login call in a function and returning it's response.

I am breaking down different features into functions and was wondering how I can return the response this facebook call generates to be used elsewhere.

function facebook_login()
{
    FB.login(function(response) {
       // handle the response
       console.log('in facebook_login function');
       console.dir(response.authResponse);
       return response;
    }, {scope: 'publish_actions', return_scopes: true});
}

var response_from_facebook_login_function = facebook_login();
도움이 되었습니까?

해결책

Ajax is async, so you need to use a callback function. Try this:

function facebook_login(call_back){
//etc
console.dir(response.authResponse);
call_back(response);
//etc

facebook_login(saveResponse);

function saveResponse(response){
    var response_from_facebook_login_function=response;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top