views:

168

answers:

3

Hey guys,

To give you a simple use case - on my website, I display the comments posted by the facebook users. For each comment I display the facebook users photo using the fb:profile-pic tag and a fb like button.

This page renders properly and everything displays well. Now when the users want to read older comments, they click on the "More" link

Using Jquery, I pull the older comments and in the javascript build the content adding the fb:profile-pic and the fb:like tags

But these tags dont show up. Do we need to reload it or something. Thanks for your help

A: 

In short, you can't use these tags...there are server-side tags that actually render as something else in the HTML sent to the client.

If you want to use facebook tags, you must render them server-side and pull the resulting HTML, rather than constructing the HTML using those tags client-side...which is just creating invalid HTML the browser doesn't understand.

For example the same in true in other languages. Here's an example in ASP.Net:

<asp:TextBox />

Renders as:

<input type="text" />

But the tag itself, the server-side markup is completely invalid in the client world...many languages operate like this, the same goes for facebook tags.

Nick Craver
How do I render these tags on server side. But then how would I create this entire string. Each comment is a div block and everything is aligned as to where the like button should appear - where the profile pic should show up. So how would I do this on the server side. I can create the entire string on server side and send it over but I just tried that it doesnt work
Gublooo
A: 

how do I do that - like right now I build my entire string say comment="<div>I love icecream<br/><fb:profile-pic uid='xxx'></fb:profile-pic></div>" Then I would do $("#myswipes").html(comment); So how would I reload.

you can use $.ajax(), say

$('a.moreComment').click(function(){
    $.ajax({
        url: 'some/url.php',
        success : function(comment){
            $("#myswipes").html(comment);
        }
    });
})

some/url.php should be in the server that can correctly render and return this line, <div>I love icecream<br/><fb:profile-picuid='xxx'></fb:profile-pic></div>

Reigel
What difference does it make rendering the same line on server side vs client side. I just tried your approach it doesnt work
Gublooo
if you can display `some/url.php` in the browser with no problem, then that should work...
Reigel
if I return any other string - that displays fine - but when I return an fb tag string like <fb:profile-pic - it does not show up
Gublooo
how did you display `<fb:profile-pic` in the other pages then ? you can use that same thing...
Reigel
+2  A: 

First make sure the FBML is being inserted into the DOM with an inspector. If so, all you need to do is tell Facebook to convert the FBML tags to HTML tags so your browser can render it. With the Graph API you call FB.XHTML.parse http://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse using the Javascript SDK. Here's an example from my code:

$('#list').append('<fb:name uid="4"></fb:name>');
FB.XFBML.parse(document.getElementById('list'));
jcmoney
thankyou thankyou thankyou - l love you - you saved so much of my time..........thats exactly what I needed - thanks again
Gublooo