开发者

Redirect after FB App Request

开发者 https://www.devze.com 2023-04-08 05:13 出处:网络
I found some sample code that does fb requests: But my goal is to redirect after this jquery post? Im not familiar with jquery post....

I found some sample code that does fb requests:

But my goal is to redirect after this jquery post? Im not familiar with jquery post.... This code just brings the dialogue box then closes. I want to refresh the page or redirect to another. I am sending the requests to fbrequests which executes some php code that stores request info to my db on my server开发者_StackOverflow中文版. I tried putting the redirect there but it doesnt work.

Its

   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");

              }
});

}


Remove the wrapping jQuery(function(){}); and just use:

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

Also use the below to join the request_ids instead of your code:

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

Taken from my tutorial: How To: Handle Application Requests Using The Facebook Graph API

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号