gpt4 book ai didi

javascript - Facebook javascript 与 RoR 集成不起作用

转载 作者:行者123 更新时间:2023-11-28 09:47:24 26 4
gpt4 key购买 nike

使用 Javascript FB.getLoginStatus 登录 Facebook 在一种情况下有效,但在另一种情况下无效。

这有效:

//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>

我不明白为什么第二个代码不起作用。谢谢!

最佳答案

<script type="text/javascript"> 
{
f1()
}
</script>

去掉大括号并添加分号就可以了:

<script type="text/javascript"> 
f1();
</script>

关于javascript - Facebook javascript 与 RoR 集成不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11596901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com