0

我想执行三个动作。

  1. 如果用户已经登录;使用ajax重定向到没有页面加载的新页面
  2. 如果已登录但未获得我的授权,app则告诉他这样做
  3. 如果未登录查看登录按钮。

这是我的尝试:

if (response.status === 'connected') {

    $.ajax({
 type: "POST",
 url: "url.php",
 success: function(r) 
  {
    window.location = 'url.php';   // **This ajax code does not work. What is the error?**
  },
});

  } else if (response.status === 'not_authorized') {

//What to do here to ask for subscription with my ID?    

  } else {

  }
 });

我的实际代码:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head> </head>
<body style="height: 560px">

<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
    FB.init({
        appId      : '132292862', // Set YOUR APP ID
        status     : true, // check login status
        cookie     : true, // enable cookies to allow the server to access the session
        xfbml      : true,  // parse XFBML
        oauth        : true
    });

    FB.Event.subscribe('auth.authResponseChange', function(response) 
    {
    if (response.status === 'connected') 
        {
        document.getElementById("log").innerHTML =  "You're connected to Facebook <a href='#' onClick='logout()'>log out</a>";
        document.getElementById("status").innerHTML='';}    
        else if (response.status === 'not_authorized') 
        {
        document.getElementById("log").innerHTML =  "Connection failed";
        } 
        else 
        {
        document.getElementById("log").innerHTML =  "You're logged out";
        }
    }); 
};

(function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return; alert('ok');}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>
</body>
</html>
4

1 回答 1

0

尝试这个:

<script>
window.fbAsyncInit = function() {
    FB.init({
        appId      : 'myId', // Set YOUR APP ID
        status     : true, // check login status
        cookie     : true, // enable cookies to allow the server to access the session
        xfbml      : true,  // parse XFBML
        oauth        : true
    });

    FB.Event.subscribe('auth.authResponseChange', function(response) 
    {
    if (response.status === 'connected') 
        {
        document.getElementById("log").innerHTML =  "You're connected to Facebook <a href='#' onClick='logout()'>log out</a>";
        document.getElementById("status").innerHTML='';}    
        else if (response.status === 'not_authorized') 
        {
        document.getElementById("log").innerHTML =  "Connection failed";
        } 
        else 
        {
        document.getElementById("log").innerHTML =  "You're logged out";
        }
    }); 
};

(function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return; alert('ok');}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>
于 2013-09-18T07:36:59.847 回答