weixin_33717117 2014-03-08 00:17 采纳率: 0%
浏览 21

如何一一加载iframe


I need to load 6 iframes in page A.php. the contents of these 6 iframes are 6 sub pages: a1.php~a6.php. before each sub page is loaded, i need to do a ajax first (to change the database) and then load the sub pages. here is the problem. each sub page should be loaded one by one. that is to say, a2.php only can be loaded after a1.php is loaded. how to realize this function? because each sub page has a big size, so it needs a little bit long time to load. Every time, when a1.php isnot loaded totally, the ajax in a2.php is working (so the datatable has been changed).
Thank you very much if you can help me:)
JS:

function showpic(id,x,y)
{ 
    if (id==0)
    {
        var oBao = CreateHTTPObject();
        var url = "ajax.php";
        var sendstring="x="+x; 
        oBao.open("POST",url,false);
        oBao.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        oBao.send(sendstring); 
        oBao.onreadystatechange = function () { OnReadyStateChng();};
        document.getElementById("iframe"+id).src="a.php?y=" +y;
    }
    else
    {
        var iid=id-1;
        document.getElementById("iframe"+iid).onload=function()
        {
            var oBao = CreateHTTPObject();
            var url = "ajax.php";
            var sendstring="x="+; 
            oBao.open("POST",url,false);
            oBao.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            oBao.send(sendstring); 
            oBao.onreadystatechange = function () { OnReadyStateChng();};
            document.getElementById("iframe"+id).src="a.php?y=" +y;
        }
    }
}

PHP:

for($i=0;$i<2;$i++)
{
    for($j=0;$j<3;$j++)
    {
        $nu=$i*3+$j;
        $div="iframe".$nu;
        echo "<iframe id='$div'  height='400px' frameborder=0 ></iframe>";
        echo "<script language='JavaScript'>showpic($nu,$x,$y) ;</script></div>";
    }
}
  • 写回答

1条回答 默认 最新

  • weixin_33725270 2014-03-08 00:33
    关注

    I'm sorry but i didnt read into your code, your explanation was clear though. An ajax request always has a callback function, thats where you will get the responsetext for your request. In this anonymous callback function you can call another function which starts loading the next iframe. Just let them set the src of the frame and it will load.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄