我試圖在Facebook上發佈牆上的圖像,我用下面的代碼誤差函數:如何解決沒有定義
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXX', // replace your app id here
channelUrl : 'http://localhost/channel.html',
status : true,
cookie : true,
xfbml : true
});
};
(function(d){
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.js";
ref.parentNode.insertBefore(js, ref);
}(document));
function FBLogin(){
FB.login(function(response){
if(response.authResponse){
window.location.reload();
}
}, {scope: 'email'});
}
function post_on_wall()
{
var share_name = 'rohitashav';
var share_link = 'http://rohitashavsinghal.com';
var share_image = 'http://rohitashavsinghal.com/fb/love.jpg';
var share_caption = 'testing';
var share_description = 'test desc';
var share_redirect = 'http://rohitashavsinghal.com/';
FB.ui(
{
method: 'feed',
name: share_name,
link: share_link,
picture: share_image,
caption: share_caption,
description: share_description
//message: ''
},
function(response)
{
if (response && response.post_id)
{
alert('thanks for sharing!');
window.top.location.href = share_redirect;
}
else
{
alert('Post was not published.');
}
}
}
</script>
和創建的按鈕如下:
<input type="button" value="Post on Wall" onClick="post_on_wall();" />
當我點擊這個按鈕,然後在console
我收到以下錯誤:
post_on_wall is not defined
雖然我已經定義了這個功能
爲什麼我得到這個錯誤?
如果我關閉這個然後我得到另一個錯誤'FB沒有定義' –
@RohitashvSinghal找到另一個問題,並更新我的答案 –