【问题标题】:Thickbox does not show contents of file fetched via jQuery.get()Thickbox 不显示通过 jQuery.get() 获取的文件内容
【发布时间】:2014-03-19 09:43:59
【问题描述】:

我正在尝试在 WordPress 的 Thickbox 中打开一个 php 文件(包含 HTML 标记)。

到目前为止,我已经成功打开了Thickbox。 php 文件的 URL 也是正确的,但它的内容没有加载到厚框中。这是我的代码:

这是我的代码:

$('.add').click(function() {
    $('html').addClass('image_spe');
    num = $(this).attr('data-num');
    formfield = $('.id_img[data-num="'+num+'"]').attr('name');
    var id=$("#post_ID").val();
    jQuery.get(dialog_url, function(){ /* here, dialog_url is the URL to the PHP file*/
    var f = jQuery(window).width();
        b = jQuery(window).height();
        f = 920 < f ? 920 : f;
        f -= 80;
        l = f/2;
        b -= 84;
        tb_show('Add', "#TB_inline?post_id="+id+"&width=" + f + "&height=" + b + "&inlineId=my-dialog");
        jQuery("#TB_window").css({'width':920, 'margin-left':-l});
    });

    return false;
});

PHP 代码在这里:

<?php 
?>
  <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      </head>
      <body>
          <div id="my-dialog">
              <p>TESTING... YOU SHOULD BE ABLE TO SEE THIS IN THICKBOX</p>
          </div>
      </body>
  </html>
<?php ?>

thickbox 打开没有任何问题,并且文件的 URL 是正确的。但内容不显示。

我该怎么做?

【问题讨论】:

    标签: javascript php jquery wordpress thickbox


    【解决方案1】:

    从 HTML 周围删除 &lt;?php?&gt;

    此外,您没有对使用.get() 加载的数据做任何事情。您应该阅读文档。

    【讨论】:

    • 不。它不工作。此外,我需要保留 php 标签。我需要传递一些php参数。
    【解决方案2】:

    jQuery.get() 可能需要稍作修改。

    改变这个...

    jQuery.get(dialog_url, function(){...}
    

    ...到这里

    jQuery.get(dialog_url, function(data){
        jQuery('body').append(data);
        ...
    }
    

    希望它应该工作!

    【讨论】:

    • 工作就像一个魅力!谢谢:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    • 1970-01-01
    • 2017-01-16
    • 1970-01-01
    • 2019-02-20
    • 2020-04-17
    • 1970-01-01
    相关资源
    最近更新 更多