我尝试安装 FOSFacebook,我已经按照所有步骤操作,但我在 js 控制台中收到此错误:
未捕获的引用错误:未定义 onFbInit
我在我的底座中包括了这个法谱.html.twig:
<!-- 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>