Facebook Like Button refresh after AJAX-Load

AlexK picture AlexK · Apr 14, 2011 · Viewed 24k times · Source

I have to implement a Facebook-Likebutton where the url is taken from an ajax request... that means i set the "href"-attribute after page-load. unfortunately, at this time the url is already set, so when liking it, it will take the actual page-url as url... is there a way to refresh the likebutton?

Answer

Michael Adel Nagy picture Michael Adel Nagy · Jun 3, 2012

If you’re using jQuery, there’s a really easy and slick solution to this problem:

$(document).ajaxComplete(function(){
    try{
        FB.XFBML.parse(); 
    }catch(ex){}
});