我尝试安装 FOSFFacebook,我已按照所有步骤操作,但我在 js 控制台中收到此错误:
未捕获的 ReferenceError:onFbInit 未定义
我在我的 base.html.twig 中包含了这个 lignes:
<!-- FaceBook Init -->
{{ facebook_initialize({'xfbml': true, 'fbAsyncInit': 'onFbInit();'}) }}
{{ facebook_login_button({'autologoutlink': true}) }}
<script>
$(document).ready(function() {
function goLogIn(){
window.location = "{{ path('_security_check') }}";
}
function onFbInit() {
if (typeof(FB) != 'undefined' && FB != null ) {
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.session || response.authResponse) {
setTimeout(goLogIn, 500);
} else {
window.location = "{{ path('_security_logout') }}";
}
});
}
}
});
</script>
有人可以帮助我吗?谢谢
最佳答案
不要在 $(document).ready(function() 调用中定义这些函数。使用:
<script>
function goLogIn(){
window.location = "{{ path('_security_check') }}";
}
function onFbInit() {
if (typeof(FB) != 'undefined' && FB != null ) {
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.session || response.authResponse) {
setTimeout(goLogIn, 500);
} else {
window.location = "{{ path('_security_logout') }}";
}
});
}
}
</script>
关于javascript - FOSFFacebook Bundle 2.0 的 JS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12509294/