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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
var oO =
{
'tempoXHR': 5000,
'tempoRefresh': 5000,
'url': 'tableau.php',
connect: function(oElem, sEvType, fn, bCapture)
{
return document.addEventListener ?
oElem.addEventListener(sEvType, fn, bCapture):
oElem.attachEvent ?
oElem.attachEvent('on' + sEvType, fn):
false;
},
aTag: function(oEl, sTag)
{
return oEl.getElementsByTagName(sTag);
},
bXHRSupport: (typeof XMLHttpRequest != "undefined"),
bActiveXSupport: (window.ActiveXObject),
aMSXML: ["Microsoft.XMLHTTP",
"MSXML2.XMLHTTP", "MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.5.0",
"MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.7.0"],
createXHR: function()
{
if(oO.bXHRSupport)
return new XMLHttpRequest;
else if(oO.bActiveXSupport)
{
var iI;
iI = oO.aMSXML.length;
do
{
try
{
return new ActiveXObject(oO.aMSXML[--iI]);
}
catch(oError) { };
}
while(iI > 0);
throw new Error("L'objet oXHR n'a pas été créé");
}
},
getXHR: function(oReq)
{
var oXHR, oTimer;
oXHR = oO.createXHR();
oO.oReq = oReq;
oXHR.open(oO.oReq['method'], oO.oReq['url'], true);
oTimer = setTimeout(
function()
{
if(oXHR)
return oXHR.abort();
},
oO['tempoXHR']
);
oXHR.onreadystatechange = function()
{
if(oXHR.readyState === 4)
if(oXHR.status && /200|304/.test(oXHR.status))
{
clearTimeout(oTimer);
oO.oReq['response'] = oXHR.responseText;
if(oO.oReq['callback'])
(oO.oReq['callback'])();
}
}
oXHR.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
if(oO.oReq['method'] === 'post')
oXHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
return oO.oReq['method'] === 'get' ?
oXHR.send(null):
oXHR.send(oO.oReq['param']);
},
control: function(oEl)
{
return setInterval(
function()
{
return oO.getXHR(
{
'cible': oEl,
'url': oO['url'],
'method': 'get',
'callback': function()
{
return oO.refresh_tableau(oO.oReq['cible'], oO.oReq['response']);
}
}
);
},
oO['tempoRefresh']
);
},
refresh_tableau: function(oEl, sResponse)
{
return oEl.innerHTML = sResponse;
},
init: function()
{
var aDivs, iDiv;
aDivs = oO.aTag(document, 'div');
iDiv = aDivs.length;
do if(aDivs[--iDiv].className === 'refresh_tableau')
oO.control(aDivs[iDiv]);
while(iDiv > 0);
return true;
}
};
oO.connect(window, 'load', oO.init, false); |
Partager