Social Buttons via Ajax

  • Feb
    25

On our app we have a Blog Index page where all the post are loaded using infnite scrolling, in every post's display there are social networks buttons (Twitter, Facebook and G+) that show how many likes, tweets or +1's has. Everytime someone got down far enough to new posts to be loaded, these buttons wouldn't appear.

After fixing some other bugs with that code, I found that this buttons are displayed via a "search and replace" code, that is executed once everytime the page loads, that's why when loaded via ajax they wouldn't show.

Searching I found an answer to this problem, if you are loading social plugins via ajax you have to trigger the "search and replace" code manually with this lines of code:

Twitter: twttr.widgets.load();

G+ : gapi.plusone.go("[BUTTON_CONTAINER]");

Facebook: FB.XFBML.parse();


Posted on Feb. 25, 2014, 11:02 a.m.