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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With