我想执行三个动作。
- 如果用户已经登录;使用ajax重定向到没有页面加载的新页面
- 如果已登录但未获得我的授权,
app
则告诉他这样做 - 如果未登录查看登录按钮。
这是我的尝试:
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>