Vincent Roye
Vincent Roye

Reputation: 2851

Load Facebook Like Buttons by Ajax

I have to load a few like buttons by Ajax. I am using Jquery and I get the right html text in response. When I do :

$.ajax({
url: "/app/ajax/load.php",
    type: "POST",
    data: "accessToken="+accessToken,
    dataType: "html",
    beforeSend: function () {            
    },
    success: function (data, textStatus, xhr) {
        $('div#result').html(data);

    }        
});

The like buttons don't appear. Is there a way to fi that ?

Thank you

Upvotes: 1

Views: 3860

Answers (1)

The Alpha
The Alpha

Reputation: 146191

Try this

success: function (data, textStatus, xhr) {
    $('div#result').html(data);
    try{
        FB.XFBML.parse(); 
    }catch(ex){}
} 

After ajax call you have to initialize facebook like button again.

Upvotes: 3

Related Questions