Not sure if this will work, but maybe try passing it as a 2nd arg in the
success call:
var _this = this;
success: function(data, _this){
alert(_this.someProperty):
}
- Jack
Brook Davies wrote:
Thanks for the feecback Jack. I am using the success() method and
within that method I want to call a method on the current object. The
reason is because I have spawned multiple objects and they all fetch
data via ajaxCFC and I want the correct object to handle the result.
I could save a reference in the global scope, but that would mean I
could only have one ajax call at a time. I just wish I could pass an
object through to the callback handler so that reference would be
available in success(). I guess I could pass a string reference to the
class object to the server and have it returned an evaluated -- but
there must be a better way, no?
BrookD
------------------------------------------------------------------------
size=2 width="100%" align=center tabindex=-1>
*From:* jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED]
*On Behalf Of *Jack Killpatrick
*Sent:* October 3, 2007 6:19 PM
*To:* jquery-en@googlegroups.com
*Subject:* [jQuery] Re: AjaxCFC
Hmm, maybe create a global var to hold a ref to the scope?
var currentObj;
and in getData:
currentObj = this;
ajax call
and in dataResult:
currentObj.someProperty = data.yadda;
currentObj = null;
?
In case you don't know, the ajaxCFC also has a success callback:
$.AjaxCFC({
url: some.cfc,
method: 'doIt',
data: { yadda:'ya' },
success: function(data){
do some stuff;
}
});
I'm assuming you're calling the dataResult() function via the success
attribute, but just in case, FYI. It doesn't really change the
approach to knowing scope thing, though, AFAIK. If you try putting
"this" inside the anonymous function, it still won't know the calling
object.
- Jack
Brook Davies wrote:
Hello Jack,
Well I want to get the scope of the calling object that the function
resides in. I have multiple instances of this object:
someObj = {
getData: function(){
//cfAjax request starts here
}
,
dataResult: function(data){
// handle result from cfAjax here
}
}
a = new someObj()
b = new someObj()
// call getData on 'a' instance
a.getData();
This is where I want the cfAjax callback to be within the scope of the
'a' object or at least somehow get a reference to 'a'. How do I do that?
BrookD