Search code examples
jqueryfacebook-javascript-sdkreview

Facebook sdk script not working on reload


In my index.php I'm loading the content of a html section with a jquery function when clicking on a link:

$('#link').click(function(e) {
    e.preventDefault();
    page = "page";
    linkClick(page);        
});

function linkClick(page) {
    if (page != null){
        $('#section').load('pages/'+page+'.php');
    }

In one of the pages I'm loading several facebook reviews with the following code:

<script async defer src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.2"></script>

<div class="fb-post" 
      data-href="https://www.facebook.com/xxx/posts/xxxxxx"
      data-width="500"></div>
</div>

The reviews show correctly but if I re-load again the page, the reviews don't show anymore. I suspect that might be because I'm loading a second time the fb sdk script? I tried to include the script in the body of the main page but the reviews don't show at all.

Thanks for your help!


Solution

  • You have to parse it after loading the source dynamically:

    https://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse/