Dai un occhio anche a questo thread che segnala un bel link sulla perdita di binding in js.
Ps.
Più che altro è una questione di gusti ma avrei risolto
in questo modo (visto che quel metodo lo utilizzi solamente
all'interno di ajaxCall) e all'interno di XMLparse non ci sono
this (ad esempio this.URL darebbe undefined)
Codice PHP:
function ajaxCall(URL) {
this.URL = URL;
function XMLparse(XMLresponse) {
// parses the XML response and returns the HTML output string;
if (window.ActiveXObject) {
// MSIE:
var doc = new ActiveXObject("Microsoft.XMLDOM");
doc.async = "false";
doc.loadXML(XMLresponse);
} else {
// W3C compliant:
var parser = new DOMParser();
var doc = parser.parseFromString(XMLresponse, "text/xml");
}
var XMLdoc = doc.documentElement;
var value = XMLdoc.getElementsByTagName('value').item(0).firstChild.nodeValue;
return value;
};
this.createXmlHttp = function() {
var xmlHttp;
try {
// W3C compliant:
xmlHttp = new XMLHttpRequest();
return xmlHttp;
} catch(e) {
// MSIE:
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
return xmlHttp;
} catch(e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;
} catch(e) {
alert("Your browser does not support AJAX.");
return false;
}
}
}
};
this.getResponse = function() {
var el = document.getElementById('result');
var xmlHttp = this.createXmlHttp();
xmlHttp.onreadystatechange = function() { // qui perdo il riferimento
document.getElementById('requestStatus').innerHTML = "Request status = " + xmlHttp.readyState;
if (xmlHttp.readyState == 4) {
alert(xmlHttp===this);
document.getElementById('xmlHttpStatus').innerHTML = "HTTP status = " + xmlHttp.status;
el.innerHTML += XMLparse(xmlHttp.responseText);
}
}
var timestamp = new Date().getTime();
xmlHttp.open("GET", this.URL + "?request=" + timestamp, true);
xmlHttp.send(null);
};
}
var request = new ajaxCall("file.xml");