This is why I like using an "Ajax Service" it creates a central instance in which all requests are generated and processed through
http://positionabsolute.net/blog/2007/07/javascript-service.php On Nov 13, 5:45 am, matte <[EMAIL PROTECTED]> wrote: > Hi, > > Yes it is more straight forward but gobally replacing lots of code > seems to be a bit out of control and prone to bugs to me. > > Thanks a lot TJ. > Mert. > > On Nov 13, 12:38 pm, "T.J. Crowder" <[EMAIL PROTECTED]> wrote: > > > Hi, > > > > Do you have any thoughts or > > > suggestions on this? > > > Just that it will be fragile. The next version of Prototype might not > > have respondToReadyState, or may have it with different params, or, > > or, ... > > > Seriously, isn't it more straight-forward to do a global search and > > replace changing "new Ajax.Request(" to "createAjaxRequest(" or some > > such? > > > FWIW, > > > -- T.J. :-) > > > On Nov 13, 10:28 am, matte <[EMAIL PROTECTED]> wrote: > > > > Hi TJ, > > > > Based on your wrap recommendation I have extended prototype (wrapped > > > Ajax.request.prototype.respondToReadyState function) without modifying > > > the initialize function and source code of prototype js. Here is the > > > link to code:http://pastie.org/313738. > > > > I hope this helps someone else too. Do you have any thoughts or > > > suggestions on this? > > > > Thanks! > > > Mert. > > > > On Nov 13, 12:16 pm, "T.J. Crowder" <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > > > > I have lots of (I mean lots lots of) 'new Ajax.Request' calls in the > > > > > application source. > > > > > Global search and replace? :-) > > > > > > Maybe extending the > > > > > Ajax.Request base? > > > > > You could do that, sure, in your own copy of prototype.js; just search > > > > for Ajax.Request and modify the initialize function. You might be > > > > able to do it in your own code after loading Prototype by replacing > > > > the Ajax.Request.prototype.initialize implementation, but that gets > > > > tricky. Either option is (a bit) fragile, as it will require > > > > maintenance when Prototype is updated. > > > > > I'd probably go with search and replace. > > > > > -- T.J. :-) > > > > > On Nov 13, 9:58 am, matte <[EMAIL PROTECTED]> wrote: > > > > > > Hi TJ, > > > > > > Thank you very much! That is what i wanted. One last question though, > > > > > I have lots of (I mean lots lots of) 'new Ajax.Request' calls in the > > > > > application source. So is there a way to do this centralized instead > > > > > of replacing every 'new Ajax.Request' call. Maybe extending the > > > > > Ajax.Request base? > > > > > > Thanks. > > > > > Mert. > > > > > > On Nov 13, 11:48 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote: > > > > > > > Hi Mert, > > > > > > > You can create a factory function for requests that inserts your > > > > > > handler, something like this: > > > > > > > * * * * > > > > > > function specialSuccessStuff(transport) > > > > > > { > > > > > > // ...whatever your special onSuccess stuff is...} > > > > > > > function makeRequest(url, options) { > > > > > > var orig; > > > > > > > orig = options.onSuccess; > > > > > > if (orig) { > > > > > > options.onSuccess = function(transport) { > > > > > > specialSuccessStuff(transport); > > > > > > orig(transport); > > > > > > }; > > > > > > } else { > > > > > > options.onSuccess = specialSuccessStuff; > > > > > > } > > > > > > return new Ajax.Request(url, options);} > > > > > > > * * * * > > > > > > > ...then use makeRequest rather than new Ajax.Request for your actual > > > > > > requests. > > > > > > > Or here's another way using Function.wrap[1]: > > > > > > > * * * * > > > > > > function onSuccessWrapper(orig, transport) > > > > > > { > > > > > > // ...whatever your special onSuccess stuff is... > > > > > > > // Chain to original onSuccess handler > > > > > > orig(transport);} > > > > > > > function makeRequest(url, options) { > > > > > > > options.onSuccess = (options.onSuccess || > > > > > > Prototype.emptyFunction).wrap(onSuccessWrapper); > > > > > > return new Ajax.Request(url, options);} > > > > > > > * * * * > > > > > > > [1]http://prototypejs.org/api/function/wrap > > > > > > > HTH, > > > > > > -- > > > > > > T.J. Crowder > > > > > > tj / crowder software / com > > > > > > > On Nov 13, 9:30 am, matte <[EMAIL PROTECTED]> wrote: > > > > > > > > Hi, > > > > > > > > I have an application that uses Ajax.Request and its onSuccess > > > > > > > event > > > > > > > handler in lots of places. > > > > > > > > I need to call a function (that will check the response) before > > > > > > > all > > > > > > > these onSuccess events fired. I tried using > > > > > > > Ajax.Responders.register > > > > > > > with onComplete event but it fires after Ajax.Request's onSuccess > > > > > > > event. Any suggestions? > > > > > > > > Thanks, > > > > > > > Mert. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---
