1

我正在加载对 div 的 ajax 响应,但现在我想将它加载到中间 iframe 我尝试了以下操作,但它从来没有工作!你们能告诉我我做错了什么吗?谢谢

<script type="text/javascript">// <![CDATA[

    $(document).ready(function() {
    $.ajaxSetup({ cache: false }); 
    setInterval(function() {
    //$('#divToRefresh').load('./doit.php');

    $("#iframe").attr('blank.php','./doit.php'); //change url
    }, 20000); 
    });
    // ]]></script>


<iframe name="top" src="blank.php" id="top"  scrolling="no" noresize frameborder="0" marginwidth="0" marginheight="0" width="100%" height="79"></iframe>
<iframe NAME="middle" src="blank.php" id="middle" noresize frameborder="0" marginwidth="0" marginheight="0" width="100%" height="238" scrolling="auto"></iframe>
<iframe NAME="foot" src="blank.php" id="foot"  scrolling="no"  noresize frameborder="0" marginwidth="0" marginheight="0" width="100%" height="200"></iframe>


<div id="divToRefresh">Loading ...</div>
4

2 回答 2

1

attr 用于替换属性,您不是在说明要替换哪个属性,而是在说明该属性的值

它应该是这样的:

$("#middle").attr('src','./doit.php'); //change url

然而,这不是 ajax ......它是简单的 iframe 技术,换句话说 $.ajaxSetup({ cache: false }); 在这种情况下不使用。

于 2013-02-13T22:25:14.683 回答
0

您的 ajax 调用错误或不完整。如果你想使用 ajax 获取数据;您应该阅读jQuery.ajax() 文档。但首先,thisthisthis

另请阅读.attr() 文档。第一个参数应该是属性名称,第二个应该是值。

但; 看起来你想重定向那个页面iframe
如果是这种情况,您的选择器应该是#middle

$("#middle").attr("src", "./doit.php");

您也可以通过这样的链接(没有 jQuery 或 javascript)来完成:

<a href="./doit.php" target="middle">Do It!</a>
于 2013-02-13T22:27:32.623 回答