| View previous topic :: View next topic |
| Author |
Message |
daedge Fresher
Joined: 30 Nov 2006 Posts: 7
|
Posted: Thu Nov 30, 2006 11:34 pm Post subject: Object reference on the return function |
|
|
I'm having trouble with my object references. For instance, I call “myobject.GetSomeAJAXData();” which the inside says:
UtilClass.HTTP.SubmitXmlHttp(<some>)
That part works fine. My problem is that when the data gets processed and returned from the server, it doesn't recognize what object it was suppose to return to.
Say that the object is the following:
CODE
function myObject(){
this.variable="hellow world!";
this.callbackfunction = function(response)
{
alert(this.variable);
}
}
Below is the JavaScript function that I'm calling (It's in a library that I wrote, hence the prototyping). When I pass (into ‘callBack’) “myObject.callbackfunction” or "myObject.callbackfunction", it calls the function correctly. However, when I reference "this", it refers to the window object and not ‘myObject’, thus throwing an error when trying to access this variable.
Is there any way this could be done without resulting in an error? _________________ -Ed |
|
| Back to top |
|
 |
daedge Fresher
Joined: 30 Nov 2006 Posts: 7
|
Posted: Thu Nov 30, 2006 11:35 pm Post subject: the code... |
|
|
CODE
UtilClass.prototype.HTTP.SubmitXmlHttp=function (method,url,data,callBack,callBackError,async)
{
if (null == async) async = true;
var xmlHttp = VW.HTTP.GetXmlHttp();
xmlHttp.onreadystatechange = function()
{
if (4 == xmlHttp.readyState)
{
if (200 == xmlHttp.status)
{
if(null!=callBack)
{
var evaledCallback=eval(callBack);
evaledCallback(xmlHttp.responseText);
}
}
else if (callBackError != null)
{
callBackError(xmlHttp)
}
else
{
alert(xmlHttp.status + " : An error occurred. Please try again later.");
}
xmlHttp=null;
}
}
xmlHttp.open(method, url, async);
if (null != data)
{
data=encodeURI(data);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-Length", data.length);
}
xmlHttp.send(data);
} _________________ -Ed |
|
| Back to top |
|
 |
|