Hello, In the next code, in the event onSuccess, the value of ''i'' is always 4. for (int i=0;i<5;i++){ url += url +i; new Ajax.Request( url, { method: ''get'', onSuccess: function(transport) { $(''name'' + i ).value transport.responseText; }, }); }); } ¿Are there anyway to send parameters to the function onSuccess? Notice, I can''t modify the response on server. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
That''s because each onSuccess callback is using same "i" from its closure. Try this: ... onSuccess: function(transport) { $(''name'' + i).value = transport.responseText; }.bind(); ... -kangax On May 8, 4:12 am, inigo <fernandeza...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > In the next code, in the event onSuccess, the value of ''i'' is always > 4. > > for (int i=0;i<5;i++){ > url += url +i; > new Ajax.Request( url, { > method: ''get'', > onSuccess: function(transport) { > $(''name'' + i ).value > transport.responseText; > }, > }); > }); > > } > > ¿Are there anyway to send parameters to the function onSuccess? > Notice, I can''t modify the response on server.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Eric Ongerth
2008-May-09 02:24 UTC
Re: Send parameter to the function onSuccess on AJAX request
The relevant doc section: http://prototypejs.org/api/function/bind On May 8, 1:12 am, inigo <fernandeza...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > In the next code, in the event onSuccess, the value of ''i'' is always > 4. > > for (int i=0;i<5;i++){ > url += url +i; > new Ajax.Request( url, { > method: ''get'', > onSuccess: function(transport) { > $(''name'' + i ).value > transport.responseText; > }, > }); > }); > > } > > ¿Are there anyway to send parameters to the function onSuccess? > Notice, I can''t modify the response on server.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---