drecute
drecute

Reputation: 758

Access a local variable from a callback function

I'm trying to update a local variable in a function with the returned data from a callback function. But it's looking like the callback function doesn't have access to it.

Below is what I'm working with:

this.renderUI = function(res) {
    var connected = (res.user != null && res.user.isConnected);
    if(connected) {
      $j('#jive-modal-invite').trigger('close'); 
      var contactsData = gigya.socialize.getContacts({callback: getContacts_callback });
      console.log(contactsData);  
    }else {
      console.log('openid disconnected');
    }   
  };

  function getContacts_callback(response) {
    return response;
  }

Upvotes: 1

Views: 305

Answers (1)

0x_Anakin
0x_Anakin

Reputation: 3269

console.log(contactsData); is being executed before your callback is complete try this:

  gigya.socialize.getContacts({callback: function(response){
    contactsData['contacts'] = response;
    console.log(contactsData); 
  } }); 

Upvotes: 1

Related Questions