如何使用Ajax刷新<iframe>?

时间:2016-02-06 15:31:37

标签: javascript php jquery ajax iframe

我想使用AJAX刷新此链接 http://radiojoven.6te.net/capas.php 。我一直在努力,但无济于事。以下是我到目前为止的内容:

&#xA;&#xA;
 &lt; script&gt;&#xA; function checkRequest(){&#xA; var interval = setTimeout(function(){&#xA; $ .ajax({&#xA; url:“http://radiojoven.6te.net/capas.php”,&#xA; type:“post”, &#xA;数据类型:“html”&#xA;})&#xA; .done(function(msg){&#xA; $(“capas”)。html(msg);&#xA;})& #xA; .always(function(){&#xA; checkRequest();&#xA;});&#xA;},20000);&#xA;}&#xA;&lt; / script&gt;&# xA;  
&#xA;&#xA;

iframe我计划更​​新:

&#xA;&#xA;
 &lt; div id = “capas”&gt;&lt; iframe src =“http://radiojoven.6te.net/capas.php”&#xA; width =“1000px”height =“300px”border =“0”marginwidth =“0”&#xA; marginheight =“0”hspace =“0”vspace =“0”frameborder =“0”scrolling =“no”&gt;&lt; / iframe&gt;&lt; / div&gt;&#xA;  
& #xA;&#xA;

如果有人能帮助我完成这项工作,我将非常感激。

&#xA;&#xA;

已经感谢你了。

&# XA;

2 个答案:

答案 0 :(得分:1)

我建议一起摆脱iframe,然后使用AJAX

它永远不会更新的原因是没有正确引用capas div。

您需要$("#capas").html(msg); //注意#以引用元素的ID。

作为补充说明,您似乎并未向服务器发布任何数据,因此您可能更善于使用HTTP GET而不是HTTP POST

答案 1 :(得分:0)

看起来应该是这样的。请注意,我更改了iframe的{​​{1}}

div