Azz... questa non la sapevo!!!
Quindi se non si dichiara la variabile con "var" davanti anche se la variabile è instanziata dentro una funzione, essa è sempre globale?
quindi in teoria un work around dovrebbe essere questo giusto?
Codice PHP:
function ahah(url,target) {
document.getElementById(target).innerHTML = 'loading data...';
if (window.XMLHttpRequest) {
var req = new XMLHttpRequest();
req.onreadystatechange = function() {ahahDone(req,target);};
req.open("GET", url, true);
req.send(null);
} else if (window.ActiveXObject) {
var req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = function() {ahahDone(req,target);};
req.open("GET", url, true);
req.send();
}
}
}
function ahahDone(req,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");
Giusto per capire... che mi è venuto il dubbio!!!