// Utilisation de XHR ?
XHR = true;
function xmlHTTP(xUrl,xId) {
if (!XHR){
try{
document.getElementById(xId).innerHTML = "XHR disabled...";
}catch (e){
alert("BUG: "+xId+" n'a pu être rechargé,\n car ce n'est pas un élément de la page !");
}
document.location = xUrl;
return;
}
document.body.style.cursor = 'wait';
var xmlhttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
/*@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
try{
xmlhttp.open("GET", xUrl, true);
xmlhttp.onreadystatechange =
function() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status == 200 || xmlhttp.status == 302) /* 200 ou 302: codes HTTP pour OK */{
newHTML = xmlhttp.responseText;
}else{
newHTML = "Error "+xmlhttp.status+" ("+xmlhttp.statusText+") for url <b>"+xUrl+"</b>";
}
document.body.style.cursor = 'default';
try{
var m = newHTML;
mScripts = "";
endTag = "</script>";
while (m.indexOf("<script") >=0) {
pD = m.indexOf("<script");
pF = m.indexOf(endTag,pD);
p = m.substr(pD,pF-pD);
// concaténation des scripts
if (p.indexOf("src=") == -1){
pDF = m.indexOf(">", pD) + 1;
var p = m.substr(pDF,pF-pDF-1);
mScripts = mScripts + p;
}
// Suppression du script de la réponse reçue
m = m.substr(0,pD) + m.substr(pF+endTag.length);
}
document.getElementById(xId).innerHTML = newHTML;
// Exécution des scripts APRES chargement , au cas où le script utilise des éléments chargés
eval(mScripts);
}catch (e){
alert("BUG: "+xId+" n'a pu être rechargé:\n"+e.message+", script:"+mScripts);
}
document.body.style.cursor = 'default';
}else{
newHTML = '<H3 align="center">Loading, please wait...</H3>';
document.getElementById(xId).innerHTML = newHTML;
}
}
xmlhttp.send(null);
}catch (e){
alert('An error has occurred calling the external site: '+e);
document.body.style.cursor = 'default';
return false;
}
}
Partager