I am implementing facebook share. However I get error Uncaught ReferenceError: FB is not defined. However, if I put code inside getScript function (in code below) then it works, but only at page load.
Viewed lots of answers like this, but was not able to get the solution.
<div id="fb-root"></div>
<script>
jQuery(document).ready(function() {
jQuery.ajaxSetup({ cache: true });
jQuery.getScript('//connect.facebook.net/en_UK/all.js', function(){
window.FB.init({
appId: 'XXX',
});
jQuery('#loginbutton,#feedbutton').removeAttr('disabled');
});
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'http://XXX.website',
picture: 'http://XXX.website/logoroundTR.gif',
caption: 'MyCaption',
description: 'MyDescription'
},
function(response) {
if (response) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
});
</script>
<button><fb:like href="http://XXX.website/" layout="button_count" action="like" show_faces="true" share="true"></fb:like></button>
p.s.: Second question: How do I link the button to FB.ui function. Any easy way?