| 12
 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
 
 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Test</title>
		<script type="text/javascript">//<![CDATA[
                        var xhr=null;
                        var ajaxDelay=5000;
                        var ajaxTimer=null;
                        var ajaxinUse=false;
 
                        function ajaxCreate(){
                                var e;
                                if(xhr)return xhr;
                                if(window.XMLHttpRequest){
                                        try{xhr=new XMLHttpRequest();}
                                        catch(e){xhr=null;}
                                }
                                else if(window.ActiveXObject){
                                        try{xhr=new ActiveXObject('Msxml2.XMLHTTP');}
                                        catch(e){
                                                try {xhr=new ActiveXObject('Microsoft.XMLHTTP');}
                                                catch(e){xhr=null;}
                                        }
                                }
                                if(!xhr)alert('Impossible de créer une instance XMLHTTP');
                                return xhr;
                        }
 
                        function ajaxProc(){
                                if(ajaxinUse||!ajaxCreate())return false;
                                ajaxinUse=true;
                                xhr.open('GET','page.php?time='+Math.random(),true);
                                xhr.onreadystatechange=function(){
                                        var e;
                                        try{
                                                if(xhr.readyState===4){
                                                        if(xhr.status===200||xhr.status===0){
                                                                document.getElementById('var').innerHTML=xhr.responseText;
                                                        }
                                                        ajaxinUse=false;
                                                        ajaxTimer=setTimeout(ajaxProc,ajaxDelay);
                                                }
                                        }catch(e){
                                                try{
                                                        xhr.onreadystatechange=function(){}
                                                        xhr.abort();
                                                }catch(e){}
                                                finally{
                                                        ajaxinUse=false;
                                                        ajaxTimer=setTimeout(ajaxProc,ajaxDelay);
                                                }
                                        }
                                }
                                xhr.send(null);
                        }
 
                        window.onload=function(){ajaxProc();};
                //]]>
                </script>
	</head>
	<body>
		<div id="var"></div>
	</body>
</html> | 
Partager