var xAjax = new Object(); xAjax.Core = function () { var xmlHttp=null; var isAsynchronous = true; var isMozilla = false; var _this = this; var AJAX_LOADING="caricamento in corso..."; var isXml=false; var requestData=""; var oHTMLWaitHolder =null; var iWaitHolderHeight=""; var _callback=null; var method="GET"; // DICHIARAZIONI PUBBLICHE --------------------------------------------------- // EVENTI this.onRequestComplete=function(){} //METODI //Creazione oggetto XMLHTTP this.newRequest=function(bKeepForm){ if (!bKeepForm) requestData=""; if (window.ActiveXObject){ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); if (xmlHttp == null){ xmlHttp = new ActiveXObject ("Msxml2.XMLHTTP"); } } else if (window.XMLHttpRequest){ xmlHttp = new XMLHttpRequest(); isMozilla = true; } else{ alert("xAjax.Core non puo\' essere creato."); return false } return true; }; //Invio Richiesta this.submitRequest = function(page,callback,bKeepData){ if (xmlHttp==null)_this.newRequest(bKeepData); _callback=callback; if (requestData==""){ sendGetRequest(page); } else{ sendPostRequest(page); } xmlHttp.onreadystatechange = handleServerResponse; } // Invia una richiesta di tipo GET. function sendGetRequest(page) { xmlHttp.open("GET", page , isAsynchronous); if (isXml) { if (isMozilla) xmlHttp.overrideMimeType('text/xml'); xmlHttp.setRequestHeader("Content-Type", "text/xml"); } xmlHttp.send(null); } // Invia una richiesta di tipo POST. function sendPostRequest(page) { xmlHttp.open("POST", page , isAsynchronous); xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); if (isXml) { xmlHttp.setRequestHeader("Content-Type", "text/xml"); } xmlHttp.send(requestData); } //Distruzione oggetto XMLHTTP this.disposeRequest=function(){ requestData=""; xmlHttp=null; } this.loadScript=function(scriptName,scriptSrc){ var script = document.createElement("script"); script.type = "text/javascript"; script.id=scriptName; script.src = scriptSrc; script.defer=true; document.getElementsByTagName("head")[0].appendChild(script); //while (!checkJSExists(scriptName)){} } this.disposeScript=function(scriptName){ document.getElementsByTagName("head")[0].removeChild(scriptName); } this.isScriptLoaded=function(scriptName){ if (document.getElementById(scriptName).readyState==4 || document.getElementById(scriptName).readyState=="loaded")return true; return false; } //PROPRIETA' //Output this.getResponse=function(bXml){ return (bXml)?xmlHttp.responseXML : xmlHttp.responseText; } //Parametri da inviare this.setFormData=function(params,bAddParmas){ if (bAddParmas) requestData+=((requestData.length>0) ? "&" : "") + params; else requestData=params; } //Parametri da inviare con accodamento a quelli già esistenti this.addParamToForm=function(name,value){ requestData+=((requestData.length>0)? "&" : "") + name + "=" + escape(value); } //Generazione automatica del FORM da inviare this.buildForm=function(formName,bAddParmas){ var oPost = document.forms[formName].elements; var oOptions=null; if(!bAddParmas)requestData=""; for (i=0;i0)?"&":"") + oPost[i].name + "=" + escape(oPost[i].value); }else{ if(oPost[i].checked) requestData+=((requestData.length>0)?"&":"") + oPost[i].name + "=" + escape(oPost[i].value); } break; case "SELECT": temp=((requestData.length>0)?"&":"") + oPost[i].name + "=" oOptions=oPost[i].options for (j=0;j0) requestData+= ((requestData.length>0)? "&" : "") + selectName + "="+ temp; } //CARICAMENTO DEL MESSAGGIO DI ATTESA IN UN TAG HTML DEFINITO this.LoadingHolder=function(destination){ oHTMLWaitHolder=document.getElementById(destination); } //PERSONALIZZAZIONE DEL MESSAGGIO DI ATTESA this.setWaitMessage=function(message){ AJAX_LOADING=message; } function handleServerResponse(){ if(xmlHttp.readyState == 4){ if (_callback==null){ _this.onRequestComplete.innerHTML=xmlHttp.responseText; _this.onRequestComplete(); }else if (_callback!=""){ eval(_callback.replace("[response]","xmlHttp.responseText")); } if(oHTMLWaitHolder!=null)oHTMLWaitHolder.style.height=iWaitHolderHeight; } } }