通过Ajax发送Facebook像按钮调用Not Working

时间:2013-12-11 12:06:16

标签: php ajax facebook

我正在开发一个涉及无限滚动页面的项目。在这里,我发送整个框并在页面上的上一个/最后一个后添加它。因此,它会创建一个垂直框列表,一个在另一个之下。

这是我在ajax调用期间发送到Javascript的PHP代码:

while($row = mysql_fetch_assoc ($result)) {
        echo "<div style=\"margin-bottom:15px;\" class=\"confession_box\">";
        echo "<div style=\"font-size:17px;\">";
        if($row['name'] != "") { echo $row['name'].', ';} if($row['age'] != "") { echo $row['age'].', '; } if($row['sex'] != "") { echo $row['sex'].', '; } if($row['location'] != "") { echo $row['location']; }
        echo "</div>";
        echo "<div style=\"font-size:13px;margin-top:8px;\">Posted on: ".date("D, d M y h:i A",strtotime($row['date_time']))." </div>";
        echo "<div style=\"margin-top:20px;font-family:calibri;\">".nl2br(htmlspecialchars($row['confession']))."</div>";
        echo "<div style=\"margin-top:20px;\">";
        echo "<div id=\"fb-like-count\" style=\"float:left;width:105px;\">";
        echo "<div class=\"fb-like\" data-href=\"https://developers.facebook.com/docs/plugins/\" data-width=\"100\" data-layout=\"button_count\" href=\"http://www.confesstalk.com/post.php?id=".$row['confession_id']."\" data-action=\"like\" data-show-faces=\"true\" data-share=\"false\"></div>";
        echo "</div>";
        echo "<div id=\"comment-count-display\" style=\"margin-left:50px;\">";

        $comm_countcomm = "select count(*) from comments where confession_id=".$row['confession_id'];
        $result_countcomm = mysql_query($comm_countcomm,$conn);
        $row_countcomm = mysql_fetch_assoc ($result_countcomm);
        $countcomm = $row_countcomm['count(*)'];
        echo "<a href='post.php?id=".$row['confession_id']."'>".$countcomm." comments | Post New Comment</a>";
        echo "</div>";
        echo "</div>";
        echo "</div>";
    }

以下是我的Javascript代码来处理这个ajax响应:

$('#end_confbox').after(data);

问题在于:除了Facebook Like Button之外,所有内容都显示在HTML页面上:

echo "<div class=\"fb-like\" data-href=\"https://developers.facebook.com/docs/plugins/\" data-width=\"100\" data-layout=\"button_count\" href=\"http://www.confesstalk.com/post.php?id=".$row['confession_id']."\" data-action=\"like\" data-show-faces=\"true\" data-share=\"false\"></div>";

1 个答案:

答案 0 :(得分:2)

问题是您的代码只是为like按钮创建了标记。但是,like按钮实际上是由facebook js sdk代码生成的,该代码在页面加载时运行。 值得庆幸的是,Facebook JS SDK中有一个方法,它指示它检查新标记并生成所需的小部件:

FB.XFBML.parse