我找到了一些执行fb请求的示例代码:
但我的目标是在这个jquery帖子之后重定向?我不熟悉jquery帖子.... 此代码只会使对话框关闭。我想刷新页面或重定向到另一个页面。我发送请求到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");
}
});
}
答案 0 :(得分: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