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 prototype-scriptaculous@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to