2013-08-06 24 views
0

我有一個函數返回一個用戶ID(用戶使用Facebook登錄到該網站)。Facebook/Javascript:發送用戶ID到數據庫

FB.getLoginStatus(function(response) { 
    if (response.status === 'connected') { 
     //logging the User ID here.... 
     console.log(response.authResponse.userID); 
    } 
}); 

在後面的腳本中,我用一大堆我收到的變量來發動Ajax。

multiUploader.prototype._uploader = function(file,f){ 
    if(typeof file[f] != undefined && self._validate(file[f].type) > 0){ 
     var data = new FormData(); 
     var ids = file[f].name._unique(); 
     data.append('file',file[f]); 
     data.append('index',ids); 
     data.append('title', $(".giveawayNameInput").val()); 

     $(".dfiles[rel='"+ids+"']").find(".progress").show(); 
     $.ajax({ 
      type:"POST", 
      url:this.config.uploadUrl, 
      data:data, 
      cache: false, 
      contentType: false, 
      processData: false, 
      success:function(rponse){ 

       console.log(rponse); 
       //Spinner can be removed here... 
      } 
     }); 
    } else 
     alert("Invalid file format - "+file[f].name); 
} 

我在哪裏做data.append()我想追加我已經從第一功能接收到的用戶ID。沒有將response.authResponse.userID定義爲全局變量,如何實現這個目標?

回答

0

你可以通過調用FB.getLoginStatus函數(file,f)來做到這一點,需要在FB.getLoginStatus範圍內聲明局部變量函數(file,f)文件,F)。