Facebook and twitter buttons for ajax content

When I load content with ajax I lost, of course, some functions like the “facebook like button” or the “tweet this”. But there’s an easy way to add bind this functions again.

For example, I am adding the following template with mustache:


	{{post.title}}
	{{post.post_content}}
	
		
		Tweet
	

So then in the javascript file that you build html or render the mustche we can simply add this:

// Facebook button
FB.XFBML.parse();

// Twitter button
twttr.widgets.load();

Further reading for facebook and twitter.