“请求对话框";单击“取消"或“关闭"按钮时,requestCallback [英] "Request Dialog" requestCallback when clicking Cancel or Close button

查看:101
本文介绍了“请求对话框";单击“取消"或“关闭"按钮时,requestCallback的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Facebook应用程序开发的新手,也是JavaScript和PHP编程的新手.

I am new into Facebook application development and also newbie about JavaScript and PHP programming.

我目前正在开发Facebook应用程序,但目前仍停留在请求对话框"窗口中.

I currently developing a Facebook application but currently stuck with Request Dialog window.

出现请求对话框"时,我选择想要的朋友,然后单击发送请求",执行requestCallback(response)并按预期方式通知收到请求的朋友.但是,如果我单击取消"或蓝色的关闭按钮,则还会执行requestCallback(response),但是选定的朋友不会收到有关该请求的通知.

When the Request Dialog appears, I choose friends I want and then click "Send Requests", the requestCallback(response) are executed and friends who getting requests are notified as expected. But, If I click "Cancel" or the blue-colored close button, the requestCallback(response) is also executed but selected friends are not getting notified about the request.

这是我的代码:

function requestCallback(response)
{
    //console.log(response);
    location.href='step2.php';
}

因此,无论我单击取消"还是关闭按钮,上面的脚本仍将执行(移至我指定的step2.php页面.)

So, whether I click "Cancel" or close button, the script above are still executed (moving to page step2.php I specify.)

我想要的是当用户单击取消"按钮或关闭模式窗口按钮时,页面停留在同一页面上.

What I want is when the user clicking cancel button or close modal window button, the page stay at the same page.

有人知道如何解决这个问题吗?

Anyone know how to solve this problem?

谢谢!

推荐答案

您可以只检查Facebook 响应对象中的内容,因为无论是否发送请求,它都不会相同!

You can just check what's inside the Facebook response object, because it won't be the same if requests have been sent or not !

类似的东西:

function requestCallback(response)
{
    if(response && response.request_ids) {
         // Here, requests have been sent, facebook gives you the ids of all requests
         //console.log(response);
         location.href='step2.php';
    } else {
         // No requests sent, you can do what you want (like...nothing, and stay on the page).
    }
}

或者如果您使用的是新结构(请求2.0高效):

Or if you are using the new structure (Request 2.0 Efficient):

function requestCallback(response)
{
    if(response && response.request) {
         // Here, requests have been sent, facebook gives you the request and the array of recipients
         //console.log(response);
         location.href='step2.php';
    } else {
         // No requests sent, you can do what you want (like...nothing, and stay on the page).
    }
}

查看响应对象的结构以使您满足条件.即使您按下关闭,也会触发回调,以便有可能在用户退出对话框时发出通知.由您来确定他是否发送了请求,并按照您的意愿进行操作! :)

Look at the structure of the response object to make your condition. The callback is fired even when you hit close in order to have the possibility to notice when your user quits the dialog. It's up to you to verify if he sent requests, and act like you want ! :)

另外,重要的一点: Facebook几周前更新了其请求系统,并在您的应用程序设置中提供了"Requests 2.0".默认情况下它是关闭的,但是如果您激活它,则向人们发送请求时 response 对象的结构将发生变化.因此,您必须在回调中更新条件!

Also, something important : Facebook updated their request system a few weeks ago, making available "Requests 2.0" in your apps settings. It's turned off by default, but if you activate it, the structure of the response object when sending requests to people will change. So you'd have to update your condition in the callback !

这里介绍了所有内容: http://developers.facebook.com/blog/post/569/

Everything is explained here : http://developers.facebook.com/blog/post/569/

这篇关于“请求对话框";单击“取消"或“关闭"按钮时,requestCallback的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆