Javascript "undefined" fejl
HejJeg har et stykke Javascript der driller. Problemet er at "this.request" pludselig er "undefined" i min doCallBack() metode, selvom "this" stadig er ok.
Her er koden:
function doHttpRequest(formRef) {
if(formRef.elements.length == this.refNames.length) {
var url = "stat-search.php?";
for(var i = 0; i < formRef.elements.length; i++) {
url = url + refNames[i] + "=\"" + escape(formRef.elements[i].value) + "\";";
}
this.request.open("GET", url, true);
this.request.onreadystatechange = this.callBack;
this.request.send(null);
} else {
// throw exception
}
}
function doCallBack() {
if (this.request.readyState == 4) {
if(this.request.status == 200) {
document.getElementById("listView").innerHTML = this.request.responseText;
}
}
}
/*
Constructor
*/
function ajax(listViewRef, refNames) {
this.listView = listViewRef;
this.refNames = refNames;
this.request = null;
try {
this.request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
this.request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
this.request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
this.request = null;
}
}
}
if (this.request == null) {
// throw exception
}
this.httpRequest = doHttpRequest;
this.callBack = doCallBack;
}