ajax in object kapseln -
04-10-2007
, 11:55 AM
Hallo,
ich habe eine Web-Seite mit zig Ajax Anwendungen.
Nun wollte ich eine Klasse schreiben um die Dinge uebersichtlich zu
machen.
AjaxProc,
mit 'callProc', diese setzt die Member und sendet den Request;
mit 'calledProc', die aufgerufen wird - aber hier ist 'this.req'
leider undefined.
--------------------------------------------------------------------
//ajax
function AjaxProc()
{
this.req = null;
this.calledProc = calledProc;
this.callProc = callProc;
this.userProc = null;
}
function calledProc(req)
{
if (this.req.readyState == 4)
{
if (this.req.status == 200)
{
var result = this.req.responseText;
this.userProc(result);
req = 0;
}
}
}
function callProc(url)
{
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest)
{
this.req = new XMLHttpRequest();
alert(this.req);
this.req.onreadystatechange = this.calledProc;
this.req.open("GET", url, true);
this.req.send(null);
}
// branch for IE/Windows ActiveX version
else if (window.ActiveXObject)
{
this.req = new ActiveXObject("Microsoft.XMLHTTP");
alert(this.req);
if (this.req)
{
this.req.onreadystatechange = this.calledProc;
this.req.open("GET", url, true);
this.req.send();
}
}
}
var AjLoadTippe = null;
function loadTippe(spiel)
{
..
AjLoadTippe = new AjaxProc();
AjLoadTippe.userProc = processLoadTippe;
AjLoadTippe.callProc(url);
}
--------------------------------------------------------------------
Ich habe schon von aehnlichen Problemen gelesen - scheinbar laeuft die
automatisch aufgerufene Funktion
'calledProc' nicht im Kontext des Objects (wohl analog statischen
Funktionen in C++).
Nur wie stellt man dieses sicher.
Solong
Frank |