youngApprentice
2007-May-29 18:29 UTC
onSuccess function to run from one of several ajax requests
Pardon this question if it''s been asked many times. I''ll have a couple of functions that make Ajax calls, and I need to know how to set things up so a single function can be run on success of either ajax request. Every example I see is showing onSuccess: function(transport) etc. and need to know how to pass the response text to my own function elsewhere in the JavaScript file. TIA, youngApprentice --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jesse Farmer
2007-May-29 19:08 UTC
Re: onSuccess function to run from one of several ajax requests
This is less a prototype question that a javascript question. The syntax function(p) { return p; } creates an anonymous (unnamed) function. Thus var obj = { onSuccess: function(p) { return p; } } is an object whose onSuccess field which contains that function. You can also certainly name the function in the usual way, however. function identity(p) { return p; } var obj1 = { onSuccess: identity } var obj2 = { onSuccess: identity } Both obj1 and obj2''s onSuccess field now points to the identity function. Another way to avoid the repetition would be to create a wrapper for Ajax.Request which sets the onSuccess anonymously. On 5/29/07, youngApprentice <tomgou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Pardon this question if it''s been asked many times. > > I''ll have a couple of functions that make Ajax calls, and I need to > know how to set things up so a single function can be run on success > of either ajax request. Every example I see is showing onSuccess: > function(transport) etc. and need to know how to pass the response > text to my own function elsewhere in the JavaScript file. > > TIA, > > youngApprentice > > > > >-- Jesse E.I. Farmer e: jesse-h8Qh2m8E5SHQT0dZR+AlfA@public.gmane.org w: http://20bits.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---