Thx!!! This is exactly what i was looking for!!! I knew there was a simple solution.
Joe C On Oct 27, 11:08 am, Michel Belleville <michel.bellevi...@gmail.com> wrote: > Well, you're using $.ajax() and the context of its callbacks make this the > xhr object, so no surprise there. > > This should work as you expect : > > var myself = this; > var Zone = function(data) { > myself.someInfo = data; > myself.load = Zone_Load;}; > > var Zone_Load = function() { > $.ajax({ > type: "GET", > url: "http://localhost/foo.xml", > success: requestSuccess}); > }; > > var requestSuccess = function(data) { > myself.someInfo = $(data).find('type'); > > }; > > JavaScript allows methods to access all objects contained by the context > they're declared in (provided you don't declare nested variables overriding > existing context variables). In this case we declare "myself" and give it a > reference to the content of "this" so when this is bound to other objects we > still can use "myself" to access the desired object. > > Michel Belleville > > 2009/10/27 Joe <joecel...@gmail.com> > > > > > I am trying to access my own JS object from within an ajax call, and > > can't figure out how to get it to work. Whenever I access "this" in > > the function, it returns the ajax context and not my JS object > > context. My code looks something like this. I have a Zone object > > defined in a JS file like this: > > > //====================START CODE================ > > function Zone(data){ > > this.someInfo = data; > > this.load = Zone_Load; > > } > > > function Zone_Load(){ > > $.ajax({ > > type: "GET", > > url: "http://localhost/foo.xml", > > success: requestSuccess > > }); > > } > > > function requestSuccess(data){ > > this.someInfo = $(data).find('type'); > > } > > //====================ENDCODE================ > > > I am having problems with the last line. How do i get access to the > > JS object, so that i can set some info on it, based on the ajax call? > > > Any help would be appreciated? > > > thx, > > > Joe C