2013-01-18 25 views
0

Facebook SDK window.fbAsyncInit不在本地主機上觸發?上週工作得很好。Facebook SDK window.fbAsyncInit不在本地主機上觸發?上週工作得很好

<div id="fb-root"></div> 
<script> 
window.fbAsyncInit = function() { 
     console.log("hey"); 
     // init the FB JS SDK 
     FB.init({ 
      appId  : '***************', // App ID from the App Dashboard 
      channelUrl : '//localhost/channel.html', // Channel File 
      status  : true, // check the login status upon init? 
      cookie  : true, // set sessions 
      xfbml  : true // parse XFBML tags on this page? 
     }); 
} 
    // 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*/ true)); 
</script> 

「哎」不火在加載頁面

另外我注意到,當我註釋掉「Fb.init」頻道網址,但加:

<script src="//connect.facebook.net/en_US/all.js"></script> 

在文件的標題內,「嘿」在第一次加載頁面時觸發,但不在隨後的嘗試中觸發

更加明確。這是我的控制檯中的錯誤消息:

Uncaught SyntaxError: Unexpected token (connect.facebook.net/en_US/all/debug.js:9237 

回答

0

您錯過了在FB.init()下加載SDK。

(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));` 

https://developers.facebook.com/docs/reference/javascript/

,並確保你在App setting page設置App Domains

+0

我在我的代碼中有這部分,但它只是與window.fbAsyncInit射擊無關。我會將它添加到我上面發佈的代碼中,只是爲了明確。此外,AppDomains中的所有內容都設置正確。我的意思是,這整個過程上週工作。我真的不明白現在和之後發生了什麼...... – tehnica

+0

實際上。我想你可能會做些什麼。我最後一個函數的部分是「/ * debug */true」。在將其更改爲false後,FB.init中的一些函數再次開始工作,並且fb.AsyncInit每次都會觸發。謝謝。 – tehnica

0

目前在all.js的調試版本的渲染中存在一個錯誤 - 這會導致您的代碼無法正確執行。這將很快得到解決。

相關問題