The plan is simple, javascript sends ajax GET request to file 'localhost/test/php/test.php?a=' . The test.php file simply echos the $_GET['a'] back. Ajax response is then used as some div's innerHTML.
This workfs beautifully and as expected on firefox, but on Chrome and IE11 it just loads the page on the last iteration of the loop:
HTML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='Type=text/html; charset=utf-8'>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
Text will appear here:
<div></div>
<script src="js/script.js"></script>
</body>
</html>
Javascript
window.onload = function () {
test.init();
};
var test = {
init: function () {
var ajax = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
for ( var a = 0 ; a < 100 ; a++) {
ajax.open('GET','php/test.php?a='+a,false);
ajax.send();
ajax.onreadystatechange = function () {
if (this.status == 200 && this.readyState == 4) {
var div = document.getElementsByTagName('div');
div[0].innerHTML = ajax.responseText;
}
};
}
}
};
PHP
<?php
$a = $_GET['a'];
echo $a;
?>
What do i need to change to make this work on IE and Chrome as well?