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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>
<html>
<head>
<title>Tutoriel Ajax (XHTML + JavaScript + XML)</title>
<script type='text/JavaScript'>
var xhr = null;
function getXhr(){
if(window.XMLHttpRequest) // Firefox et autres
xhr = new XMLHttpRequest();
else if(window.ActiveXObject){ // Internet Explorer
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else { // XMLHttpRequest non supporté par le navigateur
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
xhr = false;
}
}
</script>
</head>
<body>
<?php
$ip_address='10.10.10.10';
$host_equipment='localhost';
$ini_array = parse_ini_file("../config/conf.ini");
echo'
<table border=1>
<tr>
<td>IP address</td>
<td>Host</td>
<td>Traceroute</td>
</tr>
<tr>
<td><DIV id="MyFont1">'.$ip_address.'</DIV></td>
<td><DIV id="MyFont2">'.$host_equipment.'</FONT></td>
<td><DIV id="MyFont3"></FONT></td>
</tr>
</table>';
?>
<script>
function go1(){
getXhr()
// On défini ce qu'on va faire quand on aura la réponse
xhr.onreadystatechange = function(){
// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
if(xhr.readyState == 4 && xhr.status == 200){
document.all.MyFont1.innerHTML=xhr.responseText;
}
}
xhr.open("GET","ajax.php?id=1",true);
xhr.send(null);
}
go1();
function go2(){
getXhr()
// On défini ce qu'on va faire quand on aura la réponse
xhr.onreadystatechange = function(){
// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
if(xhr.readyState == 4 && xhr.status == 200){
document.all.MyFont2.innerHTML=xhr.responseText;
}
}
xhr.open("GET","ajax.php?id=2",true);
xhr.send(null);
}
go2();
function go3(){
getXhr()
// On défini ce qu'on va faire quand on aura la réponse
xhr.onreadystatechange = function(){
// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
if(xhr.readyState == 4 && xhr.status == 200){
document.all.MyFont3.innerHTML=xhr.responseText;
}
}
xhr.open("GET","ajax.php?id=3",true);
xhr.send(null);
}
go3();
</script>
<input type='button' value='Ping N°1' onclick='go1()' />
<input type='button' value='Ping N°2' onclick='go2()' />
<input type='button' value='Traceroute' onclick='go3()' />
</body>
</html> |
Partager