codice:
// Get the HTTP Object
function getHTTPObject(){
if (window.XMLHttpRequest) return new XMLHttpRequest();
if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
else {
alert("Your browser does not support AJAX.");
return null;
}
}
// Change the value of the outputText field
function setOutput(){
if(this.readyState == 4) {
document.getElementById('txtIDrf').value = "Associato";
document.getElementById('txtIDrf').className = "txtboxAss";
document.getElementById('txtIDrfHidden').value = httpObject.responseText;
}
}
// Implement business logic
function doWork(){
var httpObject = getHTTPObject();
if (httpObject != null) {
httpObject.open("GET", "ajxLettura.php?noCache=" + new Date().getSeconds() + '' + Math.floor(Math.random() * (9999)), true);
httpObject.send(null);
httpObject.onreadystatechange = setOutput;
}
}
Devi usare variabili locali per non sovrascrivere l'oggetto XMLHttpRequest.
Oltre a ciò per evitare il bug del caching da parte di IE devi inviare un parametro aggiuntivo che fa nuovamente richiedere la pagina al server.