facebook “Like box” in ajax loaded page only loads the first time?
ajax, facebook
Solution
you can call fb par script in your page load after calling fb script
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=11111code";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
$(document).ajaxComplete(function () {
try {
FB.XFBML.parse();
} catch (ex) { }
});
Problem
I want to show the Facebook "Like box" plugin and some other FB code in a ajax loaded page. When I load it in a ordinary html page it works as it should, but when I try to put it in a ajax load page it only loads the first time, when I click on the link to load the page the second time it is not loading the page? It is only loading the page if I clear the cache. The index file init the fb code. ``` FB.init({ appId : '277065222', // App ID status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : true, // parse XFBML oauth : true }); ``` I load the ajax page with this code: ``` function loadFacebook(){ $('#container').load('http://www.manmade.se/manmade/guiden/facebook_onweb.html'); FB.XFBML.parse(); } ``` And in the ajax loaded page I have the facebook code, eg the facebook Like box.