Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery加载带有转义字符的本地iframe url,用于论文评论_Javascript_Jquery_Html_Wordpress_Disqus - Fatal编程技术网

Javascript jQuery加载带有转义字符的本地iframe url,用于论文评论

Javascript jQuery加载带有转义字符的本地iframe url,用于论文评论,javascript,jquery,html,wordpress,disqus,Javascript,Jquery,Html,Wordpress,Disqus,我正在加载一个自定义页面类型,它只是一篇文章的注释。这就是为什么当多个循环帖子在一个页面上时,我可以使用disks线程来更容易地使用 当加载具有以下结构的iFrame时,我一直会遇到这个语法错误。我的转义字符错了吗 $(".boxyComments a").click(function (event) { event.preventDefault(); var post_id = $(this).attr("rel"

我正在加载一个自定义页面类型,它只是一篇文章的注释。这就是为什么当多个循环帖子在一个页面上时,我可以使用disks线程来更容易地使用

当加载具有以下结构的
iFrame
时,我一直会遇到这个语法错误。我的转义字符错了吗

$(".boxyComments a").click(function (event) {
                    event.preventDefault();
                    var post_id = $(this).attr("rel");
    $(".commentsIframeBig")
    .get(0).contentWindow.location.href =
        $("<?php echo get_site_url(); ?>","\/ajax-post-fold\/",post_id);
实施如下:

$(".boxyComments a").click(function (event) {
                    event.preventDefault();
var postLink = $("<?php echo get_site_url(); ?>"+"\/ajax-post-fold\/"+post_id);
                    var post_id = $(this).attr("rel");
    $(".commentsIframeBig")
    .get(0).contentWindow.location.href = postLink;
应该位于
iFrame
src
属性中的URL看起来应该可以正常运行,那么为什么仍然输出此语法错误呢

更新

var postLink = "<?= site_url('\/ajax-post\/'); ?>"+post_id;

$(this).closest(".boxy").find(".commentsIframeBig")
.css("display","block")
.animate({height:  "100%"}, 500)
.get(0).contentWindow.location.href = postLink;

这是因为您将var postlink声明为jQuery对象。您只需要将其作为字符串获取,然后将其传递给iframe

var post_id = $(this).attr("rel");
var postLink = "<?= site_url('/ajax-post-fold/'); ?>"+post_id;
var post_id=$(this.attr(“rel”);
var postLink=“”+post_id;

更新2

看起来字符串毕竟不应该包含在

相反,我创建了一些变量来影响它。代码更新如下,答案如下:

var postDir = "\/ajax-post-fold\/";
var postLink = "<?= get_site_url(postDir); ?>"+"\/ajax-post-fold\/"+post_id;
var postDir=“\/ajax post fold\/”;
var postLink=“”+”\/ajax post fold\/“+post\u id;

好的,这里有完整的工作代码来完成您想要的操作。您必须为实际代码交换一些占位符:

<script>
  jQuery(document).ready(function($){$(".boxyComments a").click(function (event) {
event.preventDefault();
    var post_id = $(this).attr("rel");
var postLink = "<?= site_url('/path/'); ?>"+post_id;
    $("#myFrame").attr('src', postLink);
});
});
</script>

jQuery(文档).ready(函数($){(“.boxyComments a”)。单击(函数(事件){
event.preventDefault();
var post_id=$(this.attr(“rel”);
var postLink=“”+post_id;
$(“#myFrame”).attr('src',postLink);
});
});
以及示例div和iFrame:

<div class='boxyComments'>
<a href='#' rel='some-url'>test link</a>
</div>

<div class=".commentsIframeBig">
<iframe id='myFrame' height="500px" width="800px" src=''>     
    </iframe>
</div>


在当地进行了测试,没有问题。您可能遇到了它无法正确访问iFrame的问题。如果您可以为iFrame提供一个更简单的id。

您遇到了什么错误?为正在进行的调用添加了更多说明。我可以看出,如果没有一个完整的运行,这可能是多么神秘。我认为这是因为不允许在选择器中添加斜杠。@putvande我也这么认为,所以我更新了上面的代码。仍然收到一条错误消息,但看起来应该有效。这更接近应该得到的答案,但是
iFrame
中没有页面加载。控制台还以红色
GET输出以下错误urlhttp://www.theciv.com29698/
实际上,路径是site\u url()函数的第一个(可选)参数:。如果您使用的是get_site_url()(不同的函数,不是我使用的函数),那么第一个参数是blog id()。因此,使用site_url()并将路径传递给它。@wunderdojo您有一个很好的观点。关于
site\u url
的使用,您是对的。这样可以很好地使用参数添加路径。对我来说仍然不起作用的是添加
+post\u id
。我尝试了几种方法来添加它,但它仍然没有被固定在那里。将再次更新。很棒的工作。我昨晚设法让它工作,所以我会更新OP。这通常也是我做的!我的代码中唯一的区别是,我在path参数中为
/
使用了转义字符。另外,
var post_id=$(this.attr('rel')
是我在每个
a
中存储每个帖子的
post id
。你已经知道答案了,谢谢。
var postDir = "\/ajax-post-fold\/";
var postLink = "<?= get_site_url(postDir); ?>"+"\/ajax-post-fold\/"+post_id;
<script>
  jQuery(document).ready(function($){$(".boxyComments a").click(function (event) {
event.preventDefault();
    var post_id = $(this).attr("rel");
var postLink = "<?= site_url('/path/'); ?>"+post_id;
    $("#myFrame").attr('src', postLink);
});
});
</script>
<div class='boxyComments'>
<a href='#' rel='some-url'>test link</a>
</div>

<div class=".commentsIframeBig">
<iframe id='myFrame' height="500px" width="800px" src=''>     
    </iframe>
</div>