Facebook的喜欢和AJAX分享按钮 [英] Facebook like and share button on ajax

查看:118
本文介绍了Facebook的喜欢和AJAX分享按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景: - 正在使用AJAX来得到一个称为foo_posts的实体。在这篇文章中我使用Facebook的份额,像按钮

Background: - Am using ajax to get a entity called as "foo_posts". In this post am using facebook share and like button

{% for post in foo_posts %}
    <div class="foo">
        {{ post }}
        <div class="fb-like" data-send="true" data-width="450" data-href="http://foo/foo/detail/{{ foo.id }}/" data-show-faces="true"></div>
</div>

{%ENDFOR%} 现在,这些职位正在使用Ajax填充。

{% endfor %} Now these posts are being populated using Ajax.

问题: - 如Facebook和份额得到由

Problem: - The facebook like and share gets initialized by

$(function(d, s, id) {
              var js, fjs = d.getElementsByTagName(s)[0];
              if (d.getElementById(id)) return;
              js = d.createElement(s); js.id = id;
              js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=245185848840630";
              fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));

这是行不通的。我怎样才能调用这个函数,使得像和份额得到正确填充? 它应该被称为阿贾克斯成功的功能。 (现在我在自己页面上调用它)

This is not working. How can I call this function, so that the like and share get populated properly ? Should it be called in the ajax success function. (Right now am calling it on on page itself)

P.S: - 我想它的成功的功能。我猜我做错了。

P.S :- I tried it in the success function. I guess am doing it wrong.

推荐答案

XFBML标签只解析在Facebook JS-SDK初始化默认情况下。

XFBML tags are only parsed on Facebook JS-SDK initialization by default.

您应该叫<一href="http://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse/"><$c$c>FB.XFBML.parse()方法一旦社交插件添加到DOM呈现页面后。

You should call FB.XFBML.parse() method once you add social plugin to DOM after page is rendered.

您可以把它所有的文件或通过指定元素中进行搜索XFBML元素:

You may call it for all document or by specifying element to search XFBML elements within:

FB.XFBML.parse();
// OR
FB.XFBML.parse(DOM_ELEMENT_WHERE_AJAX_CONTENT_IS_PLACED);

这篇关于Facebook的喜欢和AJAX分享按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆