FB 应用程序请求后重定向

发布于 2024-12-07 05:21:35 字数 1395 浏览 1 评论 0原文

我发现了一些执行 fb 请求的示例代码:

但我的目标是在这个 jquery 帖子之后重定向?我对 jquery post 不熟悉...... 此代码只是打开对话框然后关闭。我想刷新页面或重定向到另一个页面。我将请求发送到 fbrequests,它执行一些 php 代码,将请求信息存储到我服务器上的数据库。我尝试将重定向放在那里,但它不起作用。

它是

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

              }
});

}

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

              }
});

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生漫 2024-12-14 05:21:35

删除包装 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(',');

取自我的教程:如何:处理应用程序请求使用 Facebook 图谱API

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文