简体   繁体   English

登录工作正常,但现在无法调用任何功能

[英]Log in works fine, but now no functions can be called

Here is my code that starts right below the opening body tag: 这是我的代码,该代码从开始body标签下面开始:

<div id="fb-root"></div>
<script>
alert("made it into the script");
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
  appId      : '360348567392858', // App ID from the App Dashboard
  channelUrl : 'http://chrisvanhorne.com/users/erosas/final/channel.html', // Channel      File for x-domain communication
  status     : true, // check the login status upon init?
  cookie     : true, // set sessions cookies to allow your server to access the session?
  xfbml      : true  // parse XFBML tags on this page?
});

// Additional initialization code such as adding Event Listeners goes here
    FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
         // User logged into FB and authorized
            testAPI();
            document.getElementById('fb-logout').style.display = 'block';
      } else if (response.status === 'not_authorized') {
        // User logged into FB but not authorized
            login();
      } else {
        // User not logged into FB
            login();
            document.getElementById('fb-logout').style.display = 'block';
      }
     });

};

    function login() {
    FB.login(function(response) {
        if (response.authResponse) {
            // connected
            alert("made it to login");
            testAPI();
        } else {
            // cancelled
        }
    });
}

function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
        console.log('Good to see you, ' + response.name + '.');
    });
}   

 // Load the SDK's source Asynchronously
 // Note that the debug version is being actively developed and might 
 // contain some type checks that are overly strict. 
 // Please report such bugs using the bugs tool.
 (function(d, debug){
 var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
 if (d.getElementById(id)) {return;}
 js = d.createElement('script'); js.id = id; js.async = true;
 js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
 ref.parentNode.insertBefore(js, ref);
 }(document, /*debug*/ false));


</script>

The log in function works fine, but afterwards no calls can be made to functions within this script tag. 登录功能可以正常工作,但此后无法对该脚本标记内的函数进行任何调用。 Not only that, but oddly enough no <script> 's with javascript in them work at all after the Facebook script code. 不仅如此,但奇怪的是,没有javascript的<script>在Facebook脚本代码之后根本无法工作。 None of the debug alert() functions are called and no calls are made(that I can tell to Facebook). 没有调用debug alert()函数,也没有进行任何调用(我可以告诉Facebook)。

Some possible issues I've considered, but am unsure about: 我已经考虑过一些可能的问题,但是不确定:

  1. I use php to call the header and footer and this code is in the header, not too sure if that affects anything loading-wise 我使用php来调用页眉和页脚,并且此代码位于页眉中,不太确定这是否会影响加载方式
  2. The domain that I access this through is password protected, that is, when I navigate to this url a window pops up and I need to log in to see the page, not too sure if that messes with Facebook's SDK/servers 我通过其访问的域受密码保护,也就是说,当我导航至该URL时,会弹出一个窗口,我需要登录以查看页面,不太确定是否与Facebook的SDK /服务器混淆
  3. Maybe there's a fairly obvious solution that I am not seeing 也许我没有看到一个相当明显的解决方案

Any help would be greatly appreciated as I am currently going crazy trying to figure this out, thanks! 任何帮助将不胜感激,因为我目前正在努力解决这个问题,谢谢!

Unbelievable, it was in part due because the code wasn't waiting for the init function to complete and because there were "bad" javascript tags in the head(not shown) that ended as: rather than . 令人难以置信,部分原因是代码没有等待init函数完成,并且因为头部(未显示)中有“坏的” javascript标记,结尾为:而不是。 Easy fix, will search harder for answers next time 易于修复,下次将更加努力地寻找答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果在console.log 中调用了相应的函数,如何打印标签。 现在它不打印标签和结果? - How can I print label if the corresponding function is called in the console.log. Now its not printing the label and result? for循环可与console.log配合使用,但不能与innerHTML配合使用? - for loop works fine with console.log but not innerHTML? 单击按钮时不会调用函数,但在控制台中可以正常工作 - Function is not called when button is clicked but works fine in console 在 JavaScript 代码中结合两个函数不起作用,但在单个函数中工作正常 - In JavaScript code combining two functions not working, but in single function works fine 如果调用日志,我如何进行单元测试 - How I can unit test if log is called 无法使用Vuejs渲染值,但控制台日志可以正常工作 - Can not render value with Vuejs, but console log work fine 我可以在JavaScript中嵌套函数吗,它们会被自动调用吗? - Can I nest functions in JavaScript, and will they be called automatically? 如何调用函数作为函数的参数? - How can functions be called as an argument for a function? 创建可以用点表示法调用的子函数 - Create sub functions that can be called by dot notation 函数内部的变量不能被调用 - The variables inside the functions can't be called
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM