2011-09-28 40 views
0

我發現了一些示例代碼,做fb請求:FB應用程序請求後重定向

但我的目標是重定向後,此jquery後?我不熟悉jquery帖子.... 這段代碼只是帶來了對話框,然後關閉。我想刷新頁面或重定向到另一個頁面。我將請求發送到執行一些php代碼的fbrequests,該代碼將請求信息存儲到我的服務器上的數據庫。我試圖把重定向放在那裏,但它不起作用。

function sendRequest(to) { 
FB.ui({method: 'apprequests', 
     message: 'data', 
     data: to, 
     title: 'Invite your Facebook friends.'}, 

     function (response) { 
       if (response && response.request_ids) { 

        //since csv, we convert to string 
        var requestIds = ""; 
        for(var i = 0; i < response.request_ids.length; i++){ 
         requestIds = requestIds + response.request_ids[i] +","; 
        } 
        //modifications 
        //now requestIds is 123,124,125, so we need to remove the last comma after the last id 
        requestIds = requestIds.substring(0,requestIds.length-1); 

        jQuery(function(){ 
         jQuery.post("fbrequests", { request_ids: requestIds }); //jquery post to send csv list of ids to php processing file 

        // window.location.href='http://mysite.com/my-friends'; 
        }); 

       } else { 

       //Do something if they don't send it. 
       //alert("Didnt send it"); 

       } 
}); 

}

回答

0

拆除包裝jQuery(function(){});,只需使用:

jQuery.post("fbrequests", { request_ids: requestIds }, function(data) { 
    // handle the response "data", refresh or redirect here 
}); 

還可以使用下面的加盟request_ids,而不是你的代碼:

var requestIds = response.request_ids.join(','); 

來自我的教程:How To: Handle Application Requests Using The Facebook Graph API

+0

Facebook剛剛發佈了請求2.0 - LINK - http://developers.facebook.com/blog/post/464/ - 這個新的更改request_ids不再提供。相反,您可以通過這種方式獲取用戶ID:var Ids = response.to.join(','); – ivias

相關問題