Hi there! [cuts] loadTemplates: function() { for(var name in this.templates) { var f = function (func,args){ return function(args2){ func(args,args2) } }(this.onTemplateLoad.bind(this),name); new Ajax.Request(this.templates[name].url, {method:''get'', onComplete: f }); } }, onTemplateLoad: function(name,originalRequest) { alert(name+": "+originalRequest.responseText); }, [cuts] that''s the only way I''ve found to pass additional parameters to Ajax.Request callbacks. Anyone sees a cleaner way? --htrex; --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Alessandro, Alessandro Curci a écrit :> var f = function (func,args){ return function(args2){ > func(args,args2) } }(this.onTemplateLoad.bind(this),name); > new Ajax.Request(this.templates[name].url, {method:''get'', > onComplete: f });This should cut it: new Ajax.Request(this.templates[name].url, { method: ''get'', onComplete: this.onTemplateLoad.bind(this, name) }); The bind method takes additional arguments that are prefixed to those occurring upon actual invocation. Since Ajax.Request will invoke your callbacks by passing it the original request first, your name here will appear first, and the transport second.> onTemplateLoad: function(name,originalRequest) { > alert(name+": "+originalRequest.responseText); > },You''ll even get a third argument, evalJSON, a boolean based on the X-JSON HTTP response header. Oh, and BTW, make sure your "this.templates" object is not an array, but an anonymous object of some sort: arrays have plenty of Prototype-induced extensions, so the for/in loop would be inappropriate in your case. ''HTH -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve ha scritto:> Hey Alessandro, > > Alessandro Curci a écrit : > >> var f = function (func,args){ return function(args2){ >> func(args,args2) } }(this.onTemplateLoad.bind(this),name); >> new Ajax.Request(this.templates[name].url, {method:''get'', >> onComplete: f }); >> > > This should cut it: > > new Ajax.Request(this.templates[name].url, { method: ''get'', > onComplete: this.onTemplateLoad.bind(this, name) > }); > > The bind method takes additional arguments that are prefixed to those > occurring upon actual invocation. Since Ajax.Request will invoke your > callbacks by passing it the original request first, your name here will > appear first, and the transport second. >it works like a charm! thank you Christophe.> >> onTemplateLoad: function(name,originalRequest) { >> alert(name+": "+originalRequest.responseText); >> }, >> > > You''ll even get a third argument, evalJSON, a boolean based on the > X-JSON HTTP response header. > >Good to know, but actually I''m loading XHTML code fragments.> Oh, and BTW, make sure your "this.templates" object is not an array, but > an anonymous object of some sort: arrays have plenty of > Prototype-induced extensions, so the for/in loop would be inappropriate > in your case. > >Of course, it''s an object.> ''HTH > >Thanks again ''HTH ! --htrex; --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---