Buon Giorno a tutti, premetto che sono neofita di ajax ed ho questo problema: il response delle due connessioni ajax viene evidenziato nell' id=costo oppure nell' id=risultati con sostituzione del contenuto dell'uno con l'altro . Come posso fare per mostrare il risultato delle connessioni ajax una parte in id=risultati ed una parte in id costo?
Vi posto anche le pagine asp a cui mi connetto a mezzo ajax. Grazie
pagina aja.asp
pagina ajax.asp
Vi posto anche le pagine asp a cui mi connetto a mezzo ajax. Grazie
HTML:
<script type="text/javascript" >
var XMLHTTP;
function miafunz(sel){
var f = document.frm;
var trova = sel.options[sel.selectedIndex].value;
f.sel_value.value=trova;
if (trova != null)
{
var url = "aja.asp?nom="+trova;
XMLHTTP = RicavaBrowser(CambioStato);
XMLHTTP.open("GET", url, true);
XMLHTTP.send(null);
}
else
{
document.getElementById("costo").innerHTML = "";
}
}
function CambioStato()
{
if (XMLHTTP.readyState == 4)
{
var R = document.getElementById("costo");
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!");
}
}</script>
<script type="text/javascript" >
var XMLHTTP;
function Richiesta(Stringa)
{
if (Stringa.length > 0)
{
var url = "ajax.asp?nome=" + Stringa.toUpperCase();
XMLHTTP = RicavaBrowser(CambioStato);
XMLHTTP.open("GET", url, true);
XMLHTTP.send(null);
}
else
{
document.getElementById("risultati").innerHTML = "";
}
}
function CambioStato()
{
if (XMLHTTP.readyState == 4)
{
var tor = document.getElementById("risultati");
tor.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!");
}
}</script>
<form name="frm">
<input type="text" onkeyup="Richiesta(this.value)">
<select name="mySelect" onchange="miafunz(this)">
<option></option>
<option>roma</option>
</select>
<INPUT type="text" name="sel_value">
</form>
<p id="costo"></p>
<br></br><br></br>
<p id="risultati"></p>
pagina aja.asp
HTML:
<%@LANGUAGE = VBScript%>
<%
Dim x
costo = Request.QueryString("nom")
If costo = "roma" Then
costo="35"
Response.Write costo
else
response.write "necessario"
End If
%>
pagina ajax.asp
HTML:
<%@LANGUAGE = VBScript%>
<%
Dim nomi(9), nome, i, risultato
nomi(1) = "Alessandro"
nomi(2) = "Alessio"
nomi(3) = "Claudio"
nomi(4) = "Davide"
nomi(5) = "Dario"
nomi(6) = "Francesco"
nomi(7) = "Giancarlo"
nomi(8) = "Luca"
nomi(9) = "Luigi"
nome = Request.QueryString("nome")
If Len(nome) > 0 Then
risultato = ""
For i = 1 To UBound(nomi)
If nome = UCase(Mid(nomi(i), 1, Len(nome))) Then
If risultato = "" Then
risultato = nomi(i)
Else
risultato = risultato & ", " & nomi(i)
End If
End If
Next
End If
If risultato = "" Then
Response.Write "Nessun risultato..."
Else
Response.Write risultato
End If
%>