ITCOOKBOOK.com

 Options

Current Time:
Thu Sep 09, 2010 10:44 am
View unanswered posts

Log in

Username:
Password:
Log me on automatically each visit

Topic Information

Object reference on the return function

 
Post new topic   Reply to topic    ITCOOKBOOK.com Forum Index -> AJAX Programming
View previous topic :: View next topic  
Author Message
daedge
Fresher


Joined: 30 Nov 2006
Posts: 7

PostPosted: Thu Nov 30, 2006 11:34 pm    Post subject: Object reference on the return function Reply with quote

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
View user's profile Send private message
daedge
Fresher


Joined: 30 Nov 2006
Posts: 7

PostPosted: Thu Nov 30, 2006 11:35 pm    Post subject: the code... Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    ITCOOKBOOK.com Forum Index -> AJAX Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Help US Help YOU

 

 

Please complete our short survey and save $17.50 on ITCOOKBOOK.COM.

 

 

Take a look at SAPTrends.com, a new blog dedicated to discussion of SAP Training trends in SAP ERP.

 

 

C# Interview Questions

 

.NET Interview Questions

 

Java Interview Questions

 

Python Interview Questions

 

ColdFusion Interview Questions

 

Linux Interview Questions

 

Linux LPIC 1 Certification Questions

 

Perl Programming Interview Questions