我越來越常見的JS錯誤「未捕獲參考錯誤:FB沒有定義」fbgetloginstatus:FB沒有定義
有很多對同一問題的問題,我已經嘗試了 計算器可用的每個解決方案但無濟於事。顯然,人們似乎有時會遇到這個問題,我一直在得到它。任何人都可以發現錯誤?我沒有使用chnnel URL文件暫時
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function()
{
// init the FB JS SDK
FB.init=({
appId : 'xxxxxxxxxxx', // App ID from the App Dashboard
//channelUrl : 'www.something.in/channel.html', // Channel File for x-domain communication
status : false, // 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
} ;
</script>
<script type="text/javascript">
// 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));
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
alert(uid) ;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
alert("not authorised");
} else {
// the user isn't logged in to Facebook.
alert("NOTHING") ;
}
});
</script>
</body>
</html>
可能重複:我只是通過請求由jQuery的Facebook的腳本,然後初始化它解決它http://facebook.stackoverflow.com/questions/5331165/fb-is-not-defined-problem –
好Sahil,我嘗試了所有在那裏發佈的解決方案。他們不工作。一個區別是,上面的鏈接中的用戶有時會得到錯誤,但我的腳本如上所述還沒有工作。 –
但我想你沒有正確地跟着他們。這些調用是異步的,你只能在FB.init()之後調用額外的代碼。在FB.Init()之後調用FB.getLoginStatus函數(其中//附加初始化代碼..寫入)。 –