Guten Abend, ich hab ein kleines Problm mit folgender JavaScript klasse:
function AjaxRequest (url, params)
{
this.url = url;
this.is_async=params.is_async;
this.method = (params.method)?params.method.toUpperCase():"GET";
this.parameter = (params.parameter)?params.parameter:null;
if (params.onSuccess)
this.onSuccess=params.onSuccess;
else {
alert("Keine onSuccess Ereignissfunktion angegeben.\n\nBitte geben Sie einen Funktion an, die beim onSuccess ausgeführt.");
return false;
}
this.onWaiting=(params.onWaiting)?params.onWaiting:this.onSuccess;
this.onFailure=(params.onFailure)?params.onFailure:this.onSuccess;
this.anfrage=null;
try {
this.anfrage=new XMLHttpRequest();
} catch(versuchmicrosoft) {
try {
this.anfrage=new ActiveXObject("Msxml2.XMLHTTP");
}catch(anderesmicrosoft) {
try {
this.anfrage=new ActiveXObject("Microsoft.XMLHTTP");
} catch(fehlschlag) {
this.anfrage=null;
}
}
}
if (!this.anfrage) {
alert ("Das Anfrageobjekt konnte nicht initialisiert werden.\n\nBitte versuchen Sie es mit einen Anderen Browser.");
return false;
}
this.checkState = function() {
if (this.readyState==2) {
anfrage.onWaiting();
} else if (this.readyState==4 && this.status==200) {
anfrage.onSuccess();
} else if (this.readyState==4 && this.status!=200) {
anfrage.onFailure();
}
}
this.sendRequest = function() {
var parameter=this.parameter;
if (this.method=="GET"){
this.anfrage.open("GET",this.is_async,this.url + "?" + parameter);
this.anfrage.onreadystatechange = this.checkState;
this.anfrage.send(null);
}
};
}
var anfrage = new AjaxRequest("http://localhost/kapitel01/boards/aktuelleBoardVerkaeufe.php",{
method:"GET",
parameter:"wort=test",
is_async: true,
onWaiting:test,
onSuccess:test,
onFailure:test
});
function test() {alert ("test");}
anfrage.sendRequest();
Die klassen funktioniert zwar, nur möchte ich sie algemein gültig machen, sprich bei this.checkState soll anstatt "anfrage.onError()" ein ausdruck stehen, der die funktion onError aus der Klasse aufruft. ich hab mit "this.onError()" versucht, aber leider ist in this das Abfrageobjekt gespeichert. also nun meine Frage : wie kriege ich das klassenobjekt herraus, ohne anfrage zu nutzen?