Cool, that works nicely. I've never actually come across the term 'closure' before in JS. Did a quick search and read a couple things (still don't quite understand exactly how that works to get the response reference?), but from my reading, should i do anything after the clousre to avoid memory leaks? This same function flow may be invoked multiple times per page depending on the nature of the event (event1 does ajax stuff, response triggers event2, etc.)
Thanks again. Michael Peters wrote: > Erin Brewer wrote: > [snip] >> Is there no way to keep my current context when the ajax onComplete >> function is triggered? > > The easiest way is to just use a closure. > >> //skip setting up my vars for the ajax call >> >> //make the ajax call >> var ajaxCall = new Ajax.Request( urlCall, >> {method: 'post', >> postBody: postFormData, >> onComplete: NamedActionResponseHandler} >> ); >> } > >> function NamedActionResponseHandler(theResponse) >> { >> var elementThatTriggeredEvent = NamedActionElement; >> >> //do stuff based on values i have encoded into the element and >> //the data returned in theResponse >> } > > change this function to return another function. Something like this: > > function NamedActionResponseHandler(NamedActionElement, etc) { > > return function(theResponse) { > //do stuff based on values i have encoded into the element and > //the data returned in theResponse > } > } > > And then call it like this: > onComplete: NamedActionResponseHandler(theElement), > > -- > Michael Peters > Developer > Plus Three, LP -- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs