jQuery load() 和 Facebook XFBML 的问题
情况
我像这样打开一个层(jQueryUI)。
$("#dialog").load('userinfo.html #layer').dialog('open');
userinfo.html 显示 Facebook 用户的照片和姓名。
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<...some code...>
<div id="layer">
<script type="text/javascript">
$(function() {
FB.init("2342342423424", "http://www.mysite.com/xd_receiver.htm");
});
</script>
<fb:profile-pic uid="200000999530485" size="square" linked="true"></fb:profile-pic> <fb:name uid="200000999530485"></fb:name>
</div>
<...some code...>
</html>
问题:
图层打开,但fbml标签未渲染! 请帮忙。我认为 load() 不会加载 js 部分。
(如果我在浏览器中打开 userinfo.html,一切正常)
The situation
I open a layer (jQueryUI) like this.
$("#dialog").load('userinfo.html #layer').dialog('open');
userinfo.html displays the photo and the name of a facebook user.
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<...some code...>
<div id="layer">
<script type="text/javascript">
$(function() {
FB.init("2342342423424", "http://www.mysite.com/xd_receiver.htm");
});
</script>
<fb:profile-pic uid="200000999530485" size="square" linked="true"></fb:profile-pic> <fb:name uid="200000999530485"></fb:name>
</div>
<...some code...>
</html>
The problem:
The layer opens but the fbml tags are not rendered!
Please help. I think load() doenst load the js-part.
(If i open the userinfo.html in the browser everything works finde)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为这应该可行:
请注意,它在加载回调中被调用,以确保 Ajax 请求已完成并且数据已在触发 XFBML 解析之前加载。
I think this should work:
Notice that it's being called in the load callback in order to ensure the Ajax request has completed and the data has been loaded before the XFBML parsing has been triggered.
据我所知,facebook 需要这个名称空间:
确保您指定了该名称空间,或者尝试为其提供 id 而不是后面的 div:
As for as I know, facebook needs this namespace:
Make sure that you are specifying that or try giving the id to it instead of the later div:
如果 FBML 标签从一开始就没有出现在页面上(即通过 ajax 将 fbml 标签加载到某个 div 中),则不会呈现它们。为了渲染它们,您需要做一些额外的工作。
首先,所有 js 内容都应移至主窗口(fb js include、fb init)。 userinfo.html 应仅包含 fbml 和 html。应在 FB.init({xfbml : false}) 中禁用自动 FBML 解析(我不记得了,它可能与自动解析一起工作,但我认为我必须将其关闭)。
您需要使用
fb:serverFbml
标记标记未来 fbml 将动态加载的位置:您的 fbml 加载脚本现在如下所示:
FBML tags are not rendered if they are not present on the page from the beginning (i.e. you load fbml tags through ajax into some div). In order to render them you would need to do some extra work.
First of all, all js stuff should be moved to your main window (fb js include, fb init). userinfo.html should contain only fbml and html. Auto FBML parsing should be disabled in
FB.init({xfbml : false})
(I don't remember, it might work with auto parsing on but I think I had to turn it off).You need to mark a place where your future fbml will be loaded dynamically with
fb:serverFbml
tag:Your fbml loading script now would look like:
如果我解析 XFBML 有一些延迟,一切都会正常。不是有dialog('open')的回调方法吗?
If i parse the XFBML with some delay, everything works fine. Isnt there a callback method for dialog('open'), is there?