function chNumeroCasuale(Da,A) { return Math.floor((A-Da+1) * Math.random() +Da); } var CaricaHTML_DatiPagina = new Array(); var req=new Array(); var semaforo=new Array(); var imgProgress = new Image(); imgProgress.src = '/img/progressbar.gif'; var chTimer=new Array(); function CaricaHTML(url, target, method, parameters, strFunzione) { //alert(url+'\n'+target+'\n'+method+'\n'+parameters+'\n'+strFunzione) if((semaforo[target]==undefined || semaforo[target]==true) && url!=undefined){ semaforo[target]=false url+=(url.indexOf('?')>0)?'&':'?'; url+='nocache='+chNumeroCasuale(0,9999); //alert(url); //out.innerHTML+=('carico pagina: '+url+'
\n'); if(method == undefined || method == '')method="get" if(imgProgress!=''){ if(document.getElementById(target)){ //document.getElementById(target).innerHTML = 'caricamento dati in corso...'; document.getElementById(target).innerHTML = ''; } } if(window.XMLHttpRequest){ req[target] = new XMLHttpRequest(); }else if(window.ActiveXObject){ req[target] = new ActiveXObject("Microsoft.XMLHTTP"); } if(req[target]){ req[target].onreadystatechange = function() { //alert(strFunzione) CaricaHTMLDone(url, target, method, strFunzione); }; req[target].open(method, url, true); if ( (method == "POST") || (method == "post") ){ //alert('post: '+url) req[target].setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req[target].send(parameters); } else req[target].send(""); } } } function CaricaHTMLDone(url, target, method, strFunzione) { var stringa //alert('readyState: '+req.readyState) //out.innerHTML+='readyState: '+req.readyState+'
' if (req[target].readyState == 4) { semaforo[target]=true; //out.innerHTML+=target+'
'; if (document.getElementById(target)){ if (req[target].status == 200) { stringa = req[target].responseText+''; //alert(stringa) //alert('è stata caricata la pagina: '+url) document.getElementById(target).innerHTML = stringa; var re re=/<\!--\$dati:(.*)\$dati-->/ var ris = req[target].responseText.match(re); if(ris && ris[1])CaricaHTML_DatiPagina[target]=ris[1] else CaricaHTML_DatiPagina[target]='' //alert(CaricaHTML_DatiPagina+'\n'+strFunzione) if(strFunzione){ //alert(strFunzione) chTimer[target]=setTimeout(strFunzione,1); } }else{ //alert("Error:\n"+req.statusText+" "+req.responseText) document.getElementById(target).innerHTML="Error:\n"+req[target].statusText+" "+req[target].responseText; CaricaHTML_DatiPagina[target]=''; } // out.innerHTML+=('è stata caricata la pagina: '+url+'
\n') } } }