Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a limit to how many times FBML.XFBML.parse() can be called per page?

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?

like image 235
anonymous Avatar asked Dec 09 '25 04:12

anonymous


1 Answers

I tried the following function and was able to call FB.XFBML.parse() multiple times:

function createFbmlNode() {
   var like = document.createElement("fb:like");
   like.setAttribute('href', 'URL_TO_LIKE');
   like.setAttribute('send', false);
   like.setAttribute('width', 450);
   like.setAttribute('show_faces', false);

   document.getElementById('response').appendChild(like);

   FB.XFBML.parse(); 
}

The Node is created in the following span:

<span id="response" style="display: block;"></span>

The like button iFrame is created from the parse method.

like image 85
Alexcode Avatar answered Dec 10 '25 18:12

Alexcode



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!