使用JavaScript登录Facebook使用FB.getLoginStatus在一种情况下工作,在另一种情况下不起作用。Facebook与JavaScript集成RoR不起作用
这工作:
//view
<script type="text/javascript">
function f1() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
FB.api('/me', function(response) {
alert(response.name + " " + response.id);
name1 = response.name;
uid1 = response.id;
});
// var uid = response.authResponse.userID;
// var accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
}
</script>
<%= content_for :body_attributes, "onload='f1();'" %>
这不起作用
// view
<script type="text/javascript">
function f1() {
// same definition as above
}
</script>
<script type="text/javascript"> {
f1()
}
</script>
我不明白,为什么第二个代码不起作用。谢谢!
谢谢李。它仍然不起作用 – user1388066 2012-07-22 01:39:39
好的。当你说它不起作用时,你是什么意思?你有错误吗?你看了控制台吗? – 2012-07-22 01:41:37
alert()语句不显示变量:name1和uid1 – user1388066 2012-07-22 02:32:40