Quote:
Originally Posted by sjd_buffa
this.callback(ajax) is undefined inside the onreadystatechange handler.
What am I doing wrong? Any help would be appreciated.
|
you don’t take into account, that any event handler changes the scope of the handler function to the executing object. in your case
this refers to
ajax, not
myAjax.
you would have to use a closure to bind the
this to the object you want:
PHP Code:
var ajax = new ...;
var objSelf = this;
function handler() {
if (ajax.readyState==4 && ajax.status==200)
objSelf.callback(ajax);
};
ajax.onreadystatechange = handler;
remember to declare all variables local, unless you must declare them global