Originariamente inviato da fcaldera
si
ma credo che la tua domanda sia un altra.
Sto facendo un po' di esperimenti
ma quando sembra che abbia risolto
nascono i problemi
Ho questa pagina asp, a_action.asp:
codice:
<% Response.Write("Ciao, Mondo!") %>
Restituisce semplicemente la stringa "Ciao, Mondo!"
Ho la pagina a.htm. Mando il codice per eventuale collaudo
codice:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
<!--
function Button1_onclick()
{
//creazione oggetto per richiesta web
var objHTTP = getXMLHttp();
//apertura connessione HTTP
//1° parametro, GET, POST, HEAD
//2° parametro, risorsa da richiedere
//3° parametro, asincrona=true, sincrona=false
objHTTP.open('GET', 'a_action.asp?r=' + Math.random(), false);
//impostazione della funzione di callback
objHTTP.onreadystatechange = function()
{
if (objHTTP.readyState == 4)
{
if (objHTTP.status != 200) { alert("ERRORE NELLA TRASMISSIONE DATI!"); return;}
var t = objHTTP.responseText;
document.getElementById("div1").innerHTML = t; alert(t);
}
};
//invio della richiesta, per GET e HEAD è null
objHTTP.send(null);
}
// --------------------------------------------------------------------
// restituisce l'oggetto che fa la richiesta http
// --------------------------------------------------------------------
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;
}
// -->
</script>
</head>
<body>
<input id="Button1" type="button" value="button" language="javascript" onclick="return Button1_onclick()" />
<div id="div1"></div>
</body>
</html>
Ebbene, con Firefox 1.5 italiano, premendo il pulsante non succede assolutamente niente, e non mi compare neanche la finestra di errore. Se faccio la richiesta asincrono, invece, funziona.
In IE funziona(ma non fa testo, naturalmente)