Il più semplice ajax ma con errori nel div di destinazione

martedì 23 gennaio 2007 - 11.33

simone.garza Profilo | Newbie

buongiorno a tutti sono in paranoia completa!
ho preso un esempio standard di chiamata ajax
e stavo cercando di migliorarlo aggiungendo la possibilità di definire il
div nel quale deve finire il risultato. ho deciso di chiamare la variabile elementoid
ma non funziona ...mi pare che il problema stia nella riga

XMLHTTP = RicavaBrowser(CambioStato(elementoid));

suggerimenti?


varXMLHTTP; function Richiesta(Stringa,elementoid) { if (Stringa.length > 0) { var url = "ajax.asp?nome=" + Stringa.toUpperCase(); XMLHTTP = RicavaBrowser(CambioStato(elementoid)); XMLHTTP.open("GET", url, true); XMLHTTP.send(null); } else { document.getElementById(a).innerHTML = ""; } } function CambioStato(elementoid) { if (XMLHTTP.readyState == 4) { var R = document.getElementById(elementoid); R.innerHTML = XMLHTTP.responseText; } } function RicavaBrowser(QualeBrowser) { if (navigator.userAgent.indexOf("MSIE") != (-1)) { var Classe = "Msxml2.XMLHTTP"; if (navigator.appVersion.indexOf("MSIE 5.5") != (-1)); { Classe = "Microsoft.XMLHTTP"; } try { OggettoXMLHTTP = new ActiveXObject(Classe); OggettoXMLHTTP.onreadystatechange = QualeBrowser; return OggettoXMLHTTP; } catch(e) { alert("Errore: l'ActiveX non verrà eseguito!"); } } else if (navigator.userAgent.indexOf("Mozilla") != (-1)) { OggettoXMLHTTP = new XMLHttpRequest(); OggettoXMLHTTP.onload = QualeBrowser; OggettoXMLHTTP.onerror = QualeBrowser; return OggettoXMLHTTP; } else { alert("L'esempio non funziona con altri browser!"); } }

amelix Profilo | Expert

>varXMLHTTP;
>
>function Richiesta(Stringa,elementoid)
>{
>if (Stringa.length > 0)
>{
>var url = "ajax.asp?nome=" + Stringa.toUpperCase();
>alert(a);
Scusa la mia ignoranza.... Ma che cosa è a?
Non è che x errore chiami un oggetto errato?

Andrea
http://www.MelisWeb.eu/

simone.garza Profilo | Newbie

no mi è restato dentro solo un alert di una variabile precedente...non c'entra nulla....

amelix Profilo | Expert

Cmq è usato altre volte.
Andrea
http://www.MelisWeb.eu/

simone.garza Profilo | Newbie

ma no c'è solo lì .....comunque non è l'alert che mi impedisce di identificare in quale id devo postare il risultato....

amelix Profilo | Expert

Vabbè...
Il codice che hai postato nella prima riga ha varXMLHTTP;
Hai dimenticato lo spazio?

Togliendo gli a (riga ~ 14) e mettendo lo spazio mi funziona.

Forse volevi fare questo?
XMLHTTP = RicavaBrowser(document.getElementById("idTest"));

Un esempio:
http://www.riccardoslanzi.com/guide/3.html

Andrea
http://www.MelisWeb.eu/

simone.garza Profilo | Newbie

ma così facendo
XMLHTTP = RicavaBrowser(document.getElementById("idTest"));
gli passi "cablato" una div unico invece io pensavo di fare

richiesta(stringa,elementodidestinazione)

ed è quell'elemento passato sottoforma di variabile che non riesce a decodificare, se lo cablo funziona anche a me, èp nel passagio da
richiesta a cambiostato che perdo il valore della variabiel elementoid e non capisco perchè

amelix Profilo | Expert

Questo era un esempio....
Ma se guardi bene cosa fa la funzione CambioStato(elementId) vedrai che da x scontato che XMLHTTP sia valorizzato... ma la sua costruzione viene fatta da RicavaBrowser.
Andrea
http://www.MelisWeb.eu/

simone.garza Profilo | Newbie

grazie ho trovato la soluzione l'errore è nelòa chiamata. posto il codice corretto se a qualcuno occorre:

function Richiesta(Stringa,elementoid) { if (Stringa.length > 0) { var url = "ajax.asp?nome=" + Stringa.toUpperCase(); XMLHTTP = RicavaBrowser(function() {CambioStato(elementoid)}); XMLHTTP.open("GET", url, true); XMLHTTP.send(null); } else { document.getElementById(a).innerHTML = ""; } } function CambioStato(elemento) { if (XMLHTTP.readyState == 4) { var R = document.getElementById(elemento); R.innerHTML = XMLHTTP.responseText; } } function RicavaBrowser(QualeBrowser) { if (navigator.userAgent.indexOf("MSIE") != (-1)) { var Classe = "Msxml2.XMLHTTP"; if (navigator.appVersion.indexOf("MSIE 5.5") != (-1)); { Classe = "Microsoft.XMLHTTP"; } try { OggettoXMLHTTP = new ActiveXObject(Classe); OggettoXMLHTTP.onreadystatechange = QualeBrowser; return OggettoXMLHTTP; } catch(e) { alert("Errore: l'ActiveX non verrà eseguito!"); } } else if (navigator.userAgent.indexOf("Mozilla") != (-1)) { OggettoXMLHTTP = new XMLHttpRequest(); OggettoXMLHTTP.onload = QualeBrowser; OggettoXMLHTTP.onerror = QualeBrowser; return OggettoXMLHTTP; } else { alert("L'esempio non funziona con altri browser!"); } }

amelix Profilo | Expert

Stavo per postarti una cosa simile...
Ho capito solo dopo cosa volevi fare.

Il problema era la funzione che xmlhandler voleva come funzione da chiamare all'arrivo dei dati.
Andrea
http://www.MelisWeb.eu/

simone.garza Profilo | Newbie

Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5