Hi zusammen!
Ich habe den Code von http://developer.mozilla.org/de/docs/AJAX:Getting_Started genommen und ihn so umgeschrieben, dass ich daraus ein Objekt machen kann.
function Ajax()
{
this.http = false;
this.doRequest = function(url_)
{
if( window.XMLHttpRequest )
{
this.http = new XMLHttpRequest();
if(this.http.overrideMimeType)
this.http.overrideMimeType('text/xml');
}
else if( window.ActiveXObject )
{
try
{
this.http = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
this.http = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {}
}
}
if( !this.http )
{
alert("Fehler!");
return false;
}
this.http.onreadystatechange = this.handleResponse;
this.http.open('GET', url_, true);
this.http.send(null);
}
this.handleResponse = function()
{
window.alert("Objekt: " + this.http); // Fehler!!!
/*if (this.http.readyState == 4)
{
if (this.http.status == 200)
{
alert(this.http.responseText);
}
else
{
alert('Bei dem Request ist ein Problem aufgetreten.');
}
}*/
}
}
Allerdings wird ausgegeben, dass this.http undefined ist. Kann mir das jemand erklären? Es ist doch eine globale Variable, die bei doRequest einen gültigen Wert zugewiesen bekommt (habe ich per alert() überprüft).
Vielen Dank! ciao, Lukas