Javascript:我的 fbAsyncInit() 方法永远不会被调用
我直接从 Facebook 开发者网站上的此页面复制代码,并且fbAsyncInit() 方法永远不会触发。我还阅读了此页面,我已经用多种不同的方式调整了代码,但我无法触发该方法。你的想法?
另外,值得一提的是,当我尝试运行此代码和 Chrome(在 Mac 上)并运行 Firebug lite 时,我收到一条错误,提示“Firebug Lite 无法在此页面中加载”
这是代码...
<html>
<head>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '1234567890', // App ID
channelUrl : '//localhost/test.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
alert("this statement never gets called either");
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
</script>
</body>
</html>
I'm copying the code right out of this page on Facebook's developer website and the fbAsyncInit() method never fires. I've also read this page, I've tweaked the code quite a few different ways, and I cannot get the method to fire. Your thoughts?
Also, for what it's worth, when I try and run this code and Chrome (on Mac) and run Firebug lite, I get an error that says "Firebug Lite cannot be loaded in this page"
Here's the code...
<html>
<head>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '1234567890', // App ID
channelUrl : '//localhost/test.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
alert("this statement never gets called either");
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
</script>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我也有同样的问题。看来我在异步加载之前在其他地方加载了 JavaScript 库
//connect.facebook.net/en_US/all.js
。这可能有点让人困惑。
我删除了过早加载标签定义,现在一切都好了。
I had the same problem. It seemed I loaded the JavaScript library
//connect.facebook.net/en_US/all.js
in some other place before the async loading.That probably confused things a bit.
I removed the premature load tag definition and now I am fine.
您应该将:更改
为:
You should change:
to:
同步加载有问题吗?
Do you have a problem with Synchronous loading?
这个答案可能太晚了,在很多情况下都没有帮助,但是,我发现我的 Firefox 浏览器在经过一些体面的工作后显然变得有点疯狂并导致了那个确切的错误......只需重新启动该死的东西
This answer is probably too late and for many instances wont help but, I found out that my Firefox browser after some decent work apparently get a little crazy and cause that exact error... just restart the damn thing
由于您的文件名为 test.html,并且 channelUrl 应该为 test.html,因此您正在创建一个循环引用。对于正确的channelUrl,它应该只包含一行
http://developers.facebook.com/docs/reference/javascript/
Since both your file is called test.html and the channelUrl is supposed to be test.html, you're creating a circular reference. For the proper channelUrl it is supposed to just contain one line
<script src="//connect.facebook.net/en_US/all.js"></script>
http://developers.facebook.com/docs/reference/javascript/
请更改您的应用程序 ID 然后开始工作
Please Change Your App ID Then Start Working