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
|
<html>
<script type="text/javascript">
// Fonction pour Ajax
function getXMLHTTP()
{
var xhr=null;
if (window.XMLHttpRequest) // Firefox et autres.
xhr = new XMLHttpRequest();
else if (window.ActiveXObject) // Internet Explorer.
{
try
{
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e1)
{
xhr = null;
}
}
}
else
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
return xhr;
}
// Div refresh.
function getDiv1(MyDiv, MyUrl) {
var xmlhttp1 = null;
var mondiv1 = document.getElementById(MyDiv);
if (!mondiv1) {
return 1;
}
if (xmlhttp1 && xmlhttp1.readyState != 0) {
xmlhttp1.abort();
}
xmlhttp1 = getXMLHTTP();
if (xmlhttp1) {
xmlhttp1.open("GET", MyUrl, true);
/* on définit ce qui doit se passer quand la page répondra */
xmlhttp1.onreadystatechange = function() {
if (xmlhttp1.readyState == 4 && xmlhttp1.responseText != '') /* 4 : état "complete" */ {
if(mondiv1.innerHTML != xmlhttp1.responseText)
{
mondiv1.innerHTML = xmlhttp1.responseText;
}
}
}
xmlhttp1.send(null);
}
}
function rafraichir()
{
getDiv1('test2', 'test2.php');
setTimeout("rafraichir()", 2000);
}
window.onload = function() { rafraichir();}
</script>
</script>
<body>
<DIV ID="test2">
</div>
</body> </html> |
Partager