Facebook的社交插件和jQuery问题 [英] Facebook Social Plugin and jQuery Issue
问题描述
我使用jQuery加载一些内容到收藏夹状DIV的web应用程序我工作。使用$ POST,我打电话保存YouTube的视频和一个Facebook评论插件,动态网页填充。
I'm using jQuery to load some content into a lightbox-like div in a web app I'm working on. Using $POST, I'm calling a dynamically populated page that holds a youtube video and a facebook comment plugin.
第一视频我打开自带的意见,但之后每个视频自带本身,SANS-评论。任何快速的想法,可能发生的事?
The first video I load comes with the comments, but each video after that comes by itself, sans-comments. Any quick ideas as to what might be happening?
这是我加载的页面。
<? $video_id = $_POST['video_id']; ?>
<object width="800" height="499">
<param name="movie" value="http://www.youtube.com/v/<? echo $video_id; ?>?modestbranding=1&version=3&hl=en_US&rel=0"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/<? echo $video_id; ?>?modestbranding=1&version=3&hl=en_US&rel=0" type="application/x-shockwave-flash" width="800" height="499" allowscriptaccess="always" allowfullscreen="true"></embed>
</object>
<h5 style="margin:35px 0 8px 0;">Comment on this Video</h2>
<div id="fb-root"></div>
<script>(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_US/all.js#xfbml=1&appId=158242874284543";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-comments" data-href="http://XXXXXXXXXXXX.com/viewvideo.php?video_id=<? echo $video_id; ?>" data-num-posts="12" data-width="800"></div>
这是导致它在调用(#view_video是保存收藏夹的股利,.video_wrapper是显示加载的信息股利。每个缩略图是与videothumb类一个div,卫生组织id是设置为YouTube视频的唯一ID):
And this is the call that brings it in (#view_video is the div that holds the lightbox, .video_wrapper is the div that displays the info that is loaded. Each thumbnail is in a div with the videothumb class, whos id is set to the youtube videos unique id):
<script>
//VIEW VIDEO
$('.videothumb').click(function() {
$('#view_video').fadeIn('fast');
this_video_id = $(this).attr('id');
$.post( 'viewvideo.php', { video_id: this_video_id },
function( data ) {
//on complete
$('.video_wrapper').html(data);
}
);
});
</script>
谢谢!
推荐答案
在加载的第一个页面,Facebook的JS SDK获得的装载以及,并分析XFBML标记在文档中。
When you load the first page, the Facebook JS SDK get’s loaded as well, and parses the XFBML tags in your document.
下次你AJAX加载页面到您的文档,JS的SDK已经嵌入到文档中,因此没有进一步发生 - 这包括XFBML标签没有新的解析
The next time you AJAX-load a page into your document, the JS SDK is already embeded into your document, so nothing further happens – and that includes no new parsing of XFBML tags.
您必须使用 FB.XFBML .parse
告诉它应该再次搜索该文档(动态添加)XFBML标签的SDK。 (preferable给它一个DOM节点作为第一个参数,以便它不会再次搜索整个文件,但只是其中的动态变化发生的部分。)
You have to use FB.XFBML.parse
to tell the SDK that it should again search the document for (dynamically added) XFBML tags. (Preferable give it a DOM node as first parameter, so that it does not search the whole document again, but just the part where dynamic changes have occured.)
这篇关于Facebook的社交插件和jQuery问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!