Ho una semplice pagina che fa una chiamata ajax.
La pagina è messa in un server 2000 e in un server 2003 e può essere richiamata da IE6 o da IE7 .
Con IE7, Firefox e Opera funziona bene.
Con IE6 succede questo.
Se il proprio sistema operativo è windows xp funziona.
Se il proprio sistema operativo è windows 2000, se la pagina richiamata è nel server 2000, funziona, se è nel server 2003 non va. Non è che dia errore, semplicemente la chiamata dura due minuti.
Io non so proprio cosa fare :master: Metto il codice sperando nel vostro aiuto:
codice:
/*--------------------------------------------------------------------------------------------------------------
PARAMETRI
---------
url = indirizzo della pagina di action, es: url = "pagina.asp?variabile=valore"
può essere '?'. In tal caso viene considerata la pagina corrente
onload = può essere l'indirizzo della funzione di ritorno, un id valido o un oggetto valido,
(l'oggetto può supportare innerHTML o value)
se = null, non viene recuperato il dato di ritorno, ma la pagina server è richiamata lo stesso
nella funzione di callback si recuperano responseText o responseXML con
var t = this.request.responseText; var tx = this.request.responseXML;
parameters = tipo "variabile1=valore1&variabile2=valore2". E' opzionale perchè i parametri
possono essere passati nell'url
onerror = funzione richiamata in caso di errore. se omessa viene richiamata la funzione di
errore predefinita defaultError
-----------------------------------------------------------------------------------------------------------------*/
function ajax(url, onload, parameters, onerror)
{
parameters = (parameters == undefined)? "" : parameters;
//parameters = parameters.replace(/\+/g, "%2B");
//creazione oggetto per richiesta web
var objHTTP = getXMLHttp();
objHTTP.open("post", url, true);
objHTTP.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
objHTTP.setRequestHeader('Content-length',parameters.length);
objHTTP.setRequestHeader('Connection', 'close');
objHTTP.onreadystatechange = function()
{
if (objHTTP.readyState == 4)
{
if (objHTTP.status == 200 || objHTTP.status == 0)
{
this.request = objHTTP;
if(onload)
{
//funzione di ritorno
if(getTypeParameter(onload) == 1) {onload.call(this);}
//identificativo tag che supporta innerHTML
else if(getTypeParameter(onload) == 2) {try {$(onload).innerHTML = this.request.responseText;} catch(e) {$(onload).innerHTML = e.message;} }
//identificativo tag che supporta value
else if(getTypeParameter(onload) == 3) {try {$(onload).value = this.request.responseText;} catch(e) {$(onload).value = e.message;} }
//oggetto tag che supporta innerHTML
else if(getTypeParameter(onload) == 4) {try {onload.innerHTML = this.request.responseText;} catch(e) {onload.innerHTML = e.message;} }
//oggetto tag che supporta value
else if(getTypeParameter(onload) == 5) {try {onload.value = this.request.responseText;} catch(e) {onload.value = e.message;} }
}
}
//else {if(onerror && typeof(onerror) == "function") {onerror(defaultError); return;}else {defaultError(); return;}}
//else {if(onerror && typeof(onerror) == "function") {onerror.call(this); return;}else {defaultError(); return;}}
else
{
this.defaultError = defaultError;
if(onerror && typeof(onerror) == "function") {onerror.call(this); return;}else {defaultError(); return;}
}
}
};
objHTTP.send(parameters);
function getXMLHttp()
{
var xmlhttp = null;
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest(); // Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera, Internet Explorer 7
}
else if(window.ActiveXObject)
{
try
{
xmlhttp = new ActiveXObject("MSXML2.XMLHTTP"); // Internet Explorer 6
}
catch(e)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer 4,5
}
}
else
{
xmlhttp = null;
}
return xmlhttp;
};
function defaultError()
{
alert("ERRORE NELLA TRASMISSIONE DATI!");
};
}
//al posto di mettere document.getElementById("div1"), mettere $("div1")
//da prototype.js
function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}
/*----------------------------------------------------------
Restituisce il tipo di parametro ricevuto
0 -> indefinito
1 -> funzione
2 -> id oggetto che supporta innerHTML
3 -> id oggetto che supporta value
4 -> oggetto che supporta innerHTML
5 -> oggetto che supporta value
6 -> vettore
-----------------------------------------------------------*/
function getTypeParameter(v)
{
if(typeof(v) == "undefined")
{
//alert("undefined");
return 0;
}
else if(typeof(v) == "function")
{
//alert("funzione");
return 1;
}
else if(typeof(v) == "string")
{
if(document.getElementById(v) != undefined)
{
if(document.getElementById(v).value != undefined)
{
//alert(" id value");
return 3;
}
else if(document.getElementById(v).innerHTML != undefined)
{
//alert("id innerHTML");
return 2;
}
}
else return 0;
}
else if(typeof(v) == "object")
{
if(v == null)
{
//alert("null");
return 0;
}
else
{
if(v.length != undefined)
{
//alert("vettore");
return 6;
}
else
{
if(v.value != undefined)
{
//alert(" oggetto value");
return 5;
}
else if(v.innerHTML != undefined)
{
//alert("oggetto innerHTML");
return 4;
}
}
}
}
//indefinito o altro
return 0;
}
//-------------------------------------------------------------
// una volta recuperato l'xml con var tx = objHTTP.responseXML;
// e il testo con var t = objHTTP.responseText;
// stabilisco se ho ricevuo xml
//-------------------------------------------------------------
function isXML(tx)
{
if(tx == null) return false;
if(tx.documentElement == null) return false;
return true;
}
//-----------------------------------------------------
//valuta il codice javascript e restituisce la stringa
//senza codice
//-----------------------------------------------------
function execJS(t)
{
var p1 = 0, p2 = 0, p3 = 0, p4 = 0;
p1 = t.indexOf("<" + "script", 0);
if(p1 == -1) return t;
p2 = t.indexOf(">", p1 + 7) + 1;
p3 = t.indexOf("<" + "/script>", p2);
p4 = p3 + 9;
var c = t.substring(p2, p3);
var s = document.createElement("script");
s.type = "text/javascript";
s.text = c;
document.getElementsByTagName("head")[0].appendChild(s);
t = t.substring(0, p1) + t.substr(p4);
return execJS(t);
}
//-----------------------------------------------------------------
//crea la stringa dei parametri da utilizzare con ajax
//-----------------------------------------------------------------
function crea_parametri(form)
{
if(typeof(form) == "undefined")
return;
else if(typeof(form) == "string")
{
var f = document.getElementById(form);
if(!f) return;
}
else if(typeof(form) == "object")
var f = form;
var elements = f.elements;
if(!elements) return;
var n = elements.length;
var s = [];
for(var i = 0; i < n; i++)
{
var element = elements[i];
var name = element.name;
if(name != "")
{
var type = element.type;
var value = encodeURIComponent(element.value);
if(type == "text" || type == "file" || type == "password" )
{
s.push(name + "=" + value);
}
else if(type == "hidden")
{
//non considero gli elementi riservati quali:
//__EVENTTARGET, __EVENTARGUMENT, __VIEWSTATE, __EVENTVALIDATION
if(name.indexOf("__", 0) == -1) s.push(name + "=" + value);
}
else if(type == "checkbox" || type == "radio" )
{
if(element.checked)
{
s.push(name + "=" + value);
}
}
else if(type == "textarea")
{
s.push(name + "=" + value);
}
else if(type == "select-one" || type == "select-multiple")
{
var c = options_value_selezionati_join(element) + "";
if(c != "") s.push(name + "=" + c);
}
}
}
s = s.join("&");
return s;
//------------------------------------------------------------
//restituisce gli elementi value selezionati da una lista
//separati da virgola
//------------------------------------------------------------
function options_value_selezionati_join(lista)
{
var s = "";
for(var i = 0; i < lista.options.length; i++)
{
if(lista.options[i].selected) s += "," + lista.options[i].value;
}
return s.substr(1);
}
}
//-------------------------------------------------------------------------------------
//restituisce i parametri riservati da asp.net
//v è il controllo o l'id del controllo che fa il submit tramite ajax
//-------------------------------------------------------------------------------------
function parametri_riservati(v)
{
if (typeof v == 'string') v = document.getElementById(v);
var result = "";
if(self.$("__EVENTTARGET")) result+= "&" + $("__EVENTTARGET").name + "=" + v.id;
if(self.$("__EVENTARGUMENT")) result+= "&" + $("__EVENTARGUMENT").name + "=" + "";
if(self.$("__VIEWSTATE")) result+= "&" + $("__VIEWSTATE").name + "=" + encodeURIComponent($("__VIEWSTATE").value);
if(self.$("__EVENTVALIDATION")) result+= "&" + $("__EVENTVALIDATION").name + "=" + encodeURIComponent($("__EVENTVALIDATION").value);
if(result.indexOf("&", 0) == 0) result = result.substr(1);
return result;
}
/*-----------------------------------------------------------------------
nella pagina c'è un iframe nascosto:
<iframe id="iframe_tmp" name="iframe_tmp" style="display:none;"></iframe>
recupero il document da una stringa, per esempio:
var pagina = "<html><body><input type='text' id='text1' value='Pinco Pallino' /></body></html>";
var d = getDocumentFromHtml(pagina);
alert(d.getElementById("text1").value);
------------------------------------------------------------------------*/
function getDocumentFromHtml(pagina)
{
var w = window.open("", document.getElementById("iframe_tmp").name);
var d = w.document;
d.open();
d.writeln(pagina);
d.close();
return d;
}