简体   繁体   English

如何一一加载iframe

[英]how load iframe one by one


I need to load 6 iframes in page A.php. 我需要在A.php页中加载6个iframe。 the contents of these 6 iframes are 6 sub pages: a1.php~a6.php. 这6个iframe的内容为6个子页面: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. 在加载每个子页面之前,我需要先做一个ajax(以更改数据库),然后加载子页面。 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. 也就是说,只有在加载a1.php之后才能加载a2.php。 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). 每次,当a1.php未完全加载时,a2.php中的ajax都在工作(因此数据表已更改)。
Thank you very much if you can help me:) 如果可以帮助我,非常感谢您:)
JS: 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: 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>";
    }
}

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. 一个ajax请求总是具有一个回调函数,那就是您将在其中获得请求的响应文本的功能。 In this anonymous callback function you can call another function which starts loading the next iframe. 在此匿名回调函数中,您可以调用另一个函数,该函数开始加载下一个iframe。 Just let them set the src of the frame and it will load. 只需让他们设置框架的src ,它就会加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM