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 execute开发者_C百科s 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.
As a work around we can try removing and reinserting the connect js before recalling the parse function. The parse function works once everytime we insert the JS file.
Please Note
FBML has been deprecated. Starting June 1, 2012 FBML apps will no longer work as all FBML endpoints will be removed.
fb:serverFbml is part of FBML
I can verify that FB.XFBML.parse() used to work. i.e. you could call it as many times as you wanted however Facebook recently broke it. Now you can only call it once.
精彩评论