views:

75

answers:

0

I have the following code to dynamically load a XFBML fragment into an Facebook IFRAME application.

The HTML:

<div id="fragment" style="display:none">
<fb:serverfbml id="fragmentfbml">
</fb:serverfbml>

The jQuery code:

<script type="text/javascript">
function loadFragment()
{
    jQuery.ajax(
    { 
        url: "xfbml_fragment.php", // contains the 
        type: "POST",
        dataType: "html",
        cache: "false",
        success: function (data)
        {
            jQuery("#fragmentfbml").html(data);
            FB.XFBML.parse();
            jQuery("#fragment").css("display","block");
        }
    });
}
</script>

The jQuery AJAX call works every time but the FB.XFBML.parse() call only works once. I've added a callback to FB.XFBML.parse() with console.log() (see below) and verified that it only executes the first time it's called.

FB.XFBML.parse(
   document.getElementbyId("fragment"),
   function( { console.log("parse called"); } )
);

Is this a known behaviour of FB.XFBML.parse() (certainly doesn't say so in the FB Javascript SDK docs) or am I just doing things wrongly here?