Era proprio questa risposta che volevo io! Mi confermi le mie teorie!Originariamente inviato da andr3a
ancora questi problemi? ... quel codice non permette chiamate multiple ma una sola alla volta poichè la variabile è globale e ogni volta che usi quella funzione sovrascrivi l'onreadystatechange e il div scritto sarà sempre quello usato nell'ultimo onreadystatechange assegnato ... usa ABC se è la semplicità che cerchi![]()
Non so come ringraziarti!!!
Giusto per curiosità... la cosa non sono riuscito a capire è come fa a sovrascrivere l'onreadystatechange... nel loro esempio la variabile "req" non è dichiarata al di fuori della funzione....
Non dovrebbe creare una nuova istanza ad ogni chiamata?
Grazie ancora per il tuo interessamento!!!Codice PHP:// qui non c'è var req = false;
function ahah(url,target) {
document.getElementById(target).innerHTML = 'loading data...';
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = function() {ahahDone(target);};
req.open("GET", url, true);
req.send(null);
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = function() {ahahDone(target);};
req.open("GET", url, true);
req.send();
}
}
}
function ahahDone(target) {
// only if req is "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200 || req.status == 304) {
results = req.responseText;
document.getElementById(target).innerHTML = results;
} else {
document.getElementById(target).innerHTML="ahah error:\n" +
req.statusText;
}
}
}
ahah("index.php","livello1");

Rispondi quotando