Gregory Hill
2006-Apr-10 21:18 UTC
RE: Re: Prototype Ajax - How to pass my own params toonComplete
That technique will not work for this case. By default, the response element is passed in to the onComplete handler as the first argument. Basically, all ''bind'' does it let you bind the ''this'' element to the function, so when you reference this.whatever in the function, the ''this'' refers to ''this'' in the scope that the event handler was defined. Calling bind with additional parameters does not work as far as I know (unless something changed recently). You can do .bindAsEventListener to make sure the event object is passed along, in the case of real event handlers, but that doesn''t apply here. I''m not sure why my suggestion earlier didn''t work. You should be able to do this: onComplete: function (theResponse) { NamedActionResponseHandler(theResponse, theElement); } function NamedActionResponseHandler (theResponse, theElement) { // work your magic } If you are sending your ajax call inside another object and need to make sure the response function is called on the same object, that is where the .bind() would be useful. Greg> -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org[mailto:rails-spinoffs-> bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Erin Brewer > Sent: Monday, April 10, 2006 3:10 PM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails-spinoffs] Re: Prototype Ajax - How to pass my ownparams> toonComplete > > I like the technique you describe here, but when i try to reference > ''theElement'' in NamedActionResponseHandler() it is not defined. > > I changed the onComplete def to: > onComplete: NamedActionResponseHandler.bind(this, theElement) > > And changed the function to > function NamedActionResponseHandler(theResponse, theElement) > > In the function I get ''theResponse'' as the returned xml still, but > ''theElement'' is undefined, am i missing something? > > > Martin Bialasinski wrote: > > On 4/10/06, Michael Peters <mpeters-aUYv5hkjw45l57MIdRCFDg@public.gmane.org> wrote: > >> change this function to return another function. Something likethis:> > > > Yes, this is also what .bind() does to form a closure without having > > to change NamedActionResponseHandler > > > >> And then call it like this: > >> onComplete: NamedActionResponseHandler(theElement), > > > > onComplete: NamedActionResponseHandler.bind(this, theElement) > > > > theElement will now be passed as an additional argument to > > NamedActionResponseHandler, when it is called via onComplete. > > > > Bye, > > Martin > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Erin Brewer
2006-Apr-10 21:57 UTC
RE: Re: Prototype Ajax - How to pass my own params toonCompl
Ok, i tried this technique again and got it to work, not sure what i did different this time (i think i was calling ''theResponse'' just ''response'' when i first tried it, but not sure why that would matter). In any event, its really nice to understand the multiple ways to accomplish this, thanks. Now if i can just get that .bind method to work as well ... ;-) -Erin Gregory Hill wrote:> That technique will not work for this case. > > By default, the response element is passed in to the onComplete handler > as the first argument. Basically, all ''bind'' does it let you bind the > ''this'' element to the function, so when you reference this.whatever in > the function, the ''this'' refers to ''this'' in the scope that the event > handler was defined. Calling bind with additional parameters does not > work as far as I know (unless something changed recently). You can do > .bindAsEventListener to make sure the event object is passed along, in > the case of real event handlers, but that doesn''t apply here. > > I''m not sure why my suggestion earlier didn''t work. You should be able > to do this: > > onComplete: function (theResponse) { > NamedActionResponseHandler(theResponse, theElement); } > > function NamedActionResponseHandler (theResponse, theElement) { > // work your magic > } > > If you are sending your ajax call inside another object and need to make > sure the response function is called on the same object, that is where > the .bind() would be useful. > > Greg > > >> -----Original Message----- >> From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs- >> bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Erin Brewer >> Sent: Monday, April 10, 2006 3:10 PM >> To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> Subject: [Rails-spinoffs] Re: Prototype Ajax - How to pass my own > params >> >> In the function I get ''theResponse'' as the returned xml still, but >> ''theElement'' is undefined, am i missing something? >> >> >> Martin Bialasinski wrote: >> > On 4/10/06, Michael Peters <mpeters-aUYv5hkjw45l57MIdRCFDg@public.gmane.org> wrote: >> >> change this function to return another function. Something like > this:-- Posted via http://www.ruby-forum.com/.
Seemingly Similar Threads
- Prototype Ajax - How to pass my own params to onComplete ?
- RE: Prototype Ajax - How to pass my own params toonComplete ?
- obtain names of variables and data from glm object
- RE: Prototype: correct useage of onComplete withAjax.PeriodicalUpdater
- Prototype: correct useage of onComplete with Ajax.PeriodicalUpdater