Ajax – Facebook comment box rendered after AJAX call

ajaxfacebookfbml

I'm trying to display a facebook comment box along with generated ajax content. I cut down all my code to a simple example where I am eveidently missing something.

My main example page http://www.gerdalouw.com/ajax/ajax.html (from the dropdown select Test Ajax to execute)

The drop down then automatically draws in http://www.gerdalouw.com/ajax/ax.html << this works fine on its own, but the FB comment box doesn't want to generate via the Ajax call.

I've tried using the FB.XFBML.parse(); function, but I am either putting it at the wrong place or I am missing something else? I guess I am missing something very obvious somewhere?

I've been going through many possible solutions to my problem on here, but just couldn't find something that worked. Anyone that can help please?

Best Answer

This shall work for you:

$('body').ajaxComplete(function(){ FB.XFBML.parse(document.body) });

It will call FB.XFBML.parse for every ajax call. So you don't need to repeat the call everywhere.