2

我尝试安装 FOSFacebook,我已按照所有步骤操作,但在 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>

有人可以帮助我吗?谢谢

4

1 回答 1

0

不要在 $(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>
于 2012-09-20T09:12:03.840 回答