1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
<?php
$q = &$_REQUEST['q'];
if (isset($q)) die($q);
?>
<html>
<head>
<script type="text/javascript">
var liste = ['un', 'deux', 'trois', 'quatre'];
var index = 0;
var ajax;
function log(str) {
document.body.appendChild(document.createTextNode(str));
document.body.appendChild(document.createElement('BR'));
}
function createAjax() {
if (window.XMLHttpRequest)
return new XMLHttpRequest(); // Firefox
else {
if (window.ActiveXObject)
return new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer
else
throw("Votre navigateur ne supporte pas AJAX !");
}
}
function submitAjax() {
if (index < liste.length) {
log('submit ' + liste[index]);
index++;
// ajax = createAjax();
ajax.open('GET', 'test.php?q=' + liste[index - 1], true);
ajax.onreadystatechange = stateChange;
ajax.send(null);
} else {
log('terminé');
}
}
function stateChange() {
log(ajax.readyState);
if (ajax.readyState == 4) {
log(ajax.status);
if (ajax.status == 200) {
log(ajax.responseText);
submitAjax();
} else {
log(ajax.status);
}
}
}
ajax = createAjax();
ajax.onreadystatechange = stateChange;
</script>
</head>
<body onLoad="submitAjax()">
</body>
</html> |