发布到facebook如何获取响应而无需刷新 [英] Post to facebook how to get responce without refreshing

查看:123
本文介绍了发布到facebook如何获取响应而无需刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户未通过在检查显示Facebook上的Facebook登录而无法通过Facebook登录,则我有此代码.

I have this code if user is not logged in through facebook on check show facebook for user to log in through facebook.

if($req_user['oauth_provider'] != "facebook")
{
   <input type="checkbox" name="fb_post" id="fb_post" value="1" onclick="facebookPermissionsGrant(); return false;">}
?>

如果用户是通过facebook登录的,则show show复选框已选中:

If user is logged in through facebook show checkbox checked:

if($req_user['oauth_provider'] == "facebook" && $CONFIG['fb_status'] == 1) {
 <input type="checkbox" name="fb_post" id="fb_post" value="1" checked>
}

我遇到的问题是,如果用户未通过Facebook登录并选中复选框,则在Facebook上输入用户名和密码.他必须再次刷新页面才能看到该框已选中. 在ajax或jquery中有没有一种方法,这样我就不必刷新页面了,如果用户登录了,它会显示复选框已选中?

Problem i am having is if user is not logged in through facebook and checks the checbox and enter username and password on facebook. He has to refresh the page again to see that box checked. Is there a way in ajax or in jquery so that i dont have to refresh the page and if user logged in it will show box checked?

推荐答案

是的. Facebook的Javascript API具有FB.Event.Subscribe,当用户的登录状态更改时,它会通知您的JavaScript.

Yes, there is. Facebook's Javascript API has got FB.Event.Subscribe, which notifies your javascript when the user's login status changes.

示例:

window.fbAsyncInit = function() {
    FB.init({
        appId  : 'YOURAPPID',
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : true,  // parse XFBML
        channelUrl  : 'http://www.yourdomain.com/channel.html', // Custom Channel URL
        oauth : true //enables OAuth 2.0
    });

    // retrieve the login status.
    FB.getLoginStatus(function(response) {
        if (response.authResponse) update_user_is_connected();
        else update_user_is_not_connected();
    });

    // This will be triggered as soon as the user logs into Facebook (through your site)
    FB.Event.subscribe('auth.login', function(response) {
        update_user_is_connected();
    });
};

您可以在此处阅读有关FB.Event.subscribe的更多信息: http ://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

You can read more about FB.Event.subscribe here: http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

这篇关于发布到facebook如何获取响应而无需刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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