...

View Full Version : Anonymous function



Me_Titus
06-14-2007, 06:35 PM
Hi guys,

I have the following code:



function doServerRequest()
{
this.ajaxArgs.ajaxObj = ClientObjects.createXmlHttpRequest();
this.checkParameters();
this.verifyProtocol();

try
{
var args = this.ajaxArgs;
var callback = this.stateChanged;

this.ajaxArgs.ajaxObj.onreadystatechange = function()
{
callback(args);
}
}
catch(ex)
{
throw (AJAX_EXCEPTION.AJAX_INSTATIATION_EXCEPTION);
}

try
{
this.ajaxArgs.ajaxObj.open(this.ajaxArgs.httpMethod, this.ajaxArgs.serverURL, this.ajaxArgs.requestMode);
this.ajaxArgs.ajaxObj.send(this.ajaxArgs.requestParam);
}
catch(ex)
{
throw (AJAX_EXCEPTION.AJAX_REQUEST_EXCEPTION);
}
}


How can I do this instead:




this.ajaxArgs.ajaxObj.onreadystatechange = function()
{
this.stateChanged(this.ajaxArgs);
}



I understand that the object does not belong to the anonymous function...

Any help is welcome,

MeTitus

rnd me
06-15-2007, 07:15 AM
i don't think the ;ast argument is correct, it sets the asynch mode.

ex:
XHRt.open(op, turl, true);

read the ajax info at w3schools.com for more info.

A1ien51
06-15-2007, 02:04 PM
var ref = this;
this.ajaxArgs.ajaxObj.onreadystatechange = function()
{
ref.stateChanged(ref.ajaxArgs);
}


Eric

Me_Titus
06-16-2007, 02:44 PM
i don't think the ;ast argument is correct, it sets the asynch mode.

ex:
XHRt.open(op, turl, true);

read the ajax info at w3schools.com for more info.


It is right my friend.

MeTitus

Me_Titus
06-16-2007, 02:45 PM
var ref = this;
this.ajaxArgs.ajaxObj.onreadystatechange = function()
{
ref.stateChanged(ref.ajaxArgs);
}


Eric

Thank you very much for your help Eric.


MeTitus



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum