View Full Version : [AJAX] Problema con IE6
Devo implementare una pagina web con delle SELECT dinamiche, la classica procedura di selezione della NAZIONE, poi della REGIONE ecc...
Su FireFox nessun problema ma su IE6 non va, la chiamata alla funzione sembra non avvenire affatto, quindi dopo aver selezionato la NAZIONE, non compare la SELECT per le REGIONI.
Incollo qui il codice :help:
<script type="text/javascript">
// inizializzo le funzioni basilari di AJAX per la selezione delle REGIONI
var myRequest = null;
function CreateXmlHttpReq(handler) {
var xmlhttp = null;
try {
xmlhttp = new XMLHttpRequest();
} catch(e) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
xmlhttp.onreadystatechange = handler;
return xmlhttp;
}
function myHandler() {
if (myRequest.readyState == 4 && myRequest.status == 200) {
e = document.getElementById("provincia");
e.innerHTML = myRequest.responseText;
}
}
function provincia(regione){
var e = document.getElementById("provincia");
myRequest = CreateXmlHttpReq(myHandler);
myRequest.open("GET","provincia.php?regione="+escape(regione));
myRequest.send(null);
}
</script>
<div id="regioni">
<select name="paese" id="q14" >
<option title="paese" onclick="provincia('IT')" value="IT">Italy
<option title="paese" onclick="provincia('UK')" value="UK">United Kingdom
</select>
</div>
<div id="provincia">
<em>Choose the country!</em>
</div>
Il file provincia.php viene chiamato e contiene la connessione al DB con la relativa funzione di visualizzazione dell'elenco delle regioni (niente di particolare...)
<script type="text/javascript">
function CreateXmlHttpReq(handler) {
var xmlhttp = null;
try {
xmlhttp = new XMLHttpRequest();
} catch(e) {
try {
//Io uso "MSXML2.XMLHTTP.3.0" e funziona con tutti gli IE
//xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
} catch(e) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlhttp;
}
function provincia(select)
{
var provincia = select.options[ select.selectedIndex ].value;
var myRequest = CreateXmlHttpReq();
myRequest.open("GET", "provincia.php?regione="+escape(provincia), true);
myRequest.onreadystatechange = function() {
if (this.readyState == 4) {
var e = document.getElementById("provincia");
e.innerHTML = this.responseText;
}
}
myRequest.send(null);
}
</script>
<div id="regioni">
<select name="paese" id="q14" onchange="provincia(this)">
<option title="paese" value="IT">Italy
<option title="paese" value="UK">United Kingdom
</select>
</div>
mmm... cosi non funziona per niente...:muro: :muro:
nessun errore javascript?
tomminno
28-01-2008, 17:06
Sicuro di avere gli ActiveX abilitati su IE?
ho controllato, sono abilitati...
ciao , questo e un pezzettino di codice che io uso nelle mie applicazioni , magari questo funziona ( se no ti posto il file x intero ) :p
function Ajax (action , queryString){
this.getXMLInstance = function() {
var XHR = null,
browserUtente = navigator.userAgent.toUpperCase();
if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object"){
XHR = new XMLHttpRequest();
}else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) {
if(browserUtente.indexOf("MSIE 5") < 0)
XHR = new ActiveXObject("Msxml2.XMLHTTP");
else
XHR = new ActiveXObject("Microsoft.XMLHTTP");
}
return XHR;
}
this.synchronizedMessage = function (){
var URL = action;
var ajax = this.getXMLInstance();
var _response = "";
ajax.open(POST , URL , false);
ajax.setRequestHeader(CONTENT_TYPE , APP);
ajax.send(queryString);
if(statusText[ajax.status] == "OK"){
_response = ajax.responseText;
}else{
// alert("Error : " + statusText[ajax.status]);
}
return _response;
}
var CONTENT_TYPE = "Content-type";
var APP = "application/x-www-form-urlencoded";
var CONTENT_LENGTH = "Content-length";
var CONNECTION = "Connection";
var CLOSE = "Close";
var POST = "POST";
var readyState = {
INATTIVO: 0,
INIZIALIZZATO: 1,
RICHIESTA: 2,
RISPOSTA: 3,
COMPLETATO: 4
};
var statusText = new Array();
statusText[100] = "Continue";
statusText[101] = "Switching Protocols";
statusText[200] = "OK";
statusText[201] = "Created";
statusText[202] = "Accepted";
statusText[203] = "Non-Authoritative Information";
statusText[204] = "No Content";
statusText[205] = "Reset Content";
statusText[206] = "Partial Content";
statusText[300] = "Multiple Choices";
statusText[301] = "Moved Permanently";
statusText[302] = "Found";
statusText[303] = "See Other";
statusText[304] = "Not Modified";
statusText[305] = "Use Proxy";
statusText[306] = "(unused, but reserved)";
statusText[307] = "Temporary Redirect";
statusText[400] = "Bad Request";
statusText[401] = "Unauthorized";
statusText[402] = "Payment Required";
statusText[403] = "Forbidden";
statusText[404] = "Risorsa Non Trovata";
statusText[405] = "Method Not Allowed";
statusText[406] = "Not Acceptable";
statusText[407] = "Proxy Authentication Required";
statusText[408] = "Request Timeout";
statusText[409] = "Conflict";
statusText[410] = "Gone";
statusText[411] = "Length Required";
statusText[412] = "Precondition Failed";
statusText[413] = "Request Entity Too Large";
statusText[414] = "Request-URI Too Long";
statusText[415] = "Unsupported Media Type";
statusText[416] = "Requested Range Not Satisfiable";
statusText[417] = "Expectation Failed";
statusText[500] = "Internal Server Error";
statusText[501] = "Not Implemented";
statusText[502] = "Bad Gateway";
statusText[503] = "Service Unavailable";
statusText[504] = "Gateway Timeout";
statusText[505] = "HTTP Version Not Supported";
statusText[509] = "Bandwidth Limit Exceeded";
}
poi nella tua funzione dovresti utilizzarlo + o - cosi
function provincia(select)
{
var provincia = select.options[ select.selectedIndex ].value;
var ajax = new Ajax("provincia.php" , "regione="+escape(provincia));
var e = document.getElementById("provincia");
e.innerHTML = ajax.synchronizedMessage();
}
}
cmq io sta roba l'ho sepre usata con java , nn so se cambia qualcosa x php ( ma penso dii no)
ho cercato ancora in rete, ma non trovo alcun aiuto...
Riporto qui sotto tutto il codice che uso, mi sembra corretto, ma ancora non riesco a capire perchè non funziona in IE6...
var myRequest = null;
function CreateXmlHttpReq(handler) {
var xmlhttp = null;
try {
xmlhttp = new XMLHttpRequest();
} catch(e) {
try {
xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
} catch(e) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
xmlhttp.onreadystatechange = handler;
return xmlhttp;
}
function myHandler() {
if (myRequest.readyState == 4 && myRequest.status == 200) {
e = document.getElementById("provincia");
e.innerHTML = myRequest.responseText;
}
}
function provincia(regione){
var e = document.getElementById("provincia");
myRequest = CreateXmlHttpReq(myHandler);
myRequest.open("GET","provincia.php?regione="+escape(regione));
myRequest.send(null);
}
texerasmo
04-02-2008, 12:17
non so se ti puo essere d'aiuto prevoa a vedere
su http://www.prototypejs.org/
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.