Wiring Facebook HTML5 like and comment elements with AJAX Wiring Facebook HTML5 like and comment elements with AJAX ajax ajax

Wiring Facebook HTML5 like and comment elements with AJAX


The (main) reason your attempt doesn't work is because of this line:

if (d.getElementById(id)) return;

i.e. the code checks whether or not the facebook script (which you added dynamically using the rest of the included code) is already there and, if it is, does not include it again. I believe the de-duplication is there for a reason, and anyway, I tested re-running the code (by ensuring the script is added twice) with no success.

I saw your note about XFBML, however calling FB.XFBML.parse() (without any arguments) seems to work even if the markup you actually used is the HTML5 one:

setTimeout(function() {    $('<div class="fb-like" data-send="false" data-layout="standard"        data-width="450" data-show-faces="false" data-colorscheme="light"       data-action="like"></div>').appendTo('#test');    FB.XFBML.parse();}, 2000);

Working example at jsFiddle.