jQuery load() 和 Facebook XFBML 的问题

发布于 2024-09-09 08:06:18 字数 873 浏览 8 评论 0原文

情况

我像这样打开一个层(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

金兰素衣 2024-09-16 08:06:18

我认为这应该可行:

$("#dialog").load('userinfo.html #layer', function() {
  FB.XFBML.parse(document.getElementById('dialog'));
});
$("#dialog").dialog('open');

请注意,它在加载回调中被调用,以确保 Ajax 请求已完成并且数据已在触发 XFBML 解析之前加载。

I think this should work:

$("#dialog").load('userinfo.html #layer', function() {
  FB.XFBML.parse(document.getElementById('dialog'));
});
$("#dialog").dialog('open');

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.

逆光飞翔i 2024-09-16 08:06:18

据我所知,facebook 需要这个名称空间:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">

确保您指定了该名称空间,或者尝试为其提供 id 而不是后面的 div:

<html id="layer" xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">

As for as I know, facebook needs this namespace:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">

Make sure that you are specifying that or try giving the id to it instead of the later div:

<html id="layer" xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
雪落纷纷 2024-09-16 08:06:18

如果 FBML 标签从一开始就没有出现在页面上(即通过 ajax 将 fbml 标签加载到某个 div 中),则不会呈现它们。为了渲染它们,您需要做一些额外的工作。

首先,所有 js 内容都应移至主窗口(fb js include、fb init)。 userinfo.html 应仅包含 fbml 和 html。应在 FB.init({xfbml : false}) 中禁用自动 FBML 解析(我不记得了,它可能与自动解析一起工作,但我认为我必须将其关闭)。

您需要使用 fb:serverFbml 标记标记未来 fbml 将动态加载的位置:

<div id="dialog">
    <fb:serverFbml id="dialog-fbml"></fb:serverFbml>
</div>

您的 fbml 加载脚本现在如下所示:

$("#dialog-fbml").load('userinfo.html #layer'); //load fbml
FB.XFBML.parse($("#dialog")[0]); //parse it
$("#dialog").dialog('open'); //show

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:

<div id="dialog">
    <fb:serverFbml id="dialog-fbml"></fb:serverFbml>
</div>

Your fbml loading script now would look like:

$("#dialog-fbml").load('userinfo.html #layer'); //load fbml
FB.XFBML.parse($("#dialog")[0]); //parse it
$("#dialog").dialog('open'); //show
剩余の解释 2024-09-16 08:06:18

如果我解析 XFBML 有一些延迟,一切都会正常。不是有dialog('open')的回调方法吗?

      $("#dialog").load('userinfo.html #layer');
      $("#dialog").dialog('open');        
      setTimeout(function() {FB.XFBML.parse(document.getElementById('#dialog'));} ,4000);

If i parse the XFBML with some delay, everything works fine. Isnt there a callback method for dialog('open'), is there?

      $("#dialog").load('userinfo.html #layer');
      $("#dialog").dialog('open');        
      setTimeout(function() {FB.XFBML.parse(document.getElementById('#dialog'));} ,4000);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文