There are 6 iframes in page A. When every iframe is loaded, it needs to send an ajax request to page B and rewrite the data in the database at first and then the src of this iframe direct to another page C (in page C, there are some calculation based on the rewritten database). After all this have been done, the next iframe will be loaded. This is a "for" loop used language php. But now there is a problem, because in page C there are a lot of calculations, it needs a little long time to calculate. When this iframe is calculating, next iframe has sent his ajax request to page B and the database has been changed. So how I can let the next iframe send his ajax request after this iframe has been loaded totally? I have tried settimeout and set the delay to 12s. but it still has the problem.
Page A:
<?php
echo " <table>";
for($i=0; $i<2; $i++) {
echo "<tr>";
for($j=0; $j<3; $j++) {
$divid="div".$i*3+$j;
echo "<iframe id=$divid frameborder='0' height=400></iframe>";
echo "<script language='JavaScript'>showpic($divid);</script></td>";
}
echo "</tr>";
}
echo "</table>";
?>
<script>
function showpic(divid) {
var url = "b.php";
var oBao = CreateHTTPObject();
var sendstring="id="+divid;
oBao.open("POST",url,false);
oBao.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
oBao.onreadystatechange = function () { OnReadyStateChng(divid);};
oBao.send(sendstring);
}
function OnReadyStateChng(divid) {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
document.getElementById(id).src="c.php?id="+divid ;
} else {
}
} else {
}
}
function CreateHTTPObject() {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch(e) {
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp=false;
}
}
return xmlhttp;
}
</script>