I am trying to setup some basic Ajax framework, and I was thinking to
use Ajax.Responders to intercept some events, but I meet the following
issues :
- First, it seems that the responders ignore an onSuccess() callback
passed through Ajax.Responders.register().
This may be a documentation error since the "Prototype 1.6 - The
Complete API Reference" says that "All callbacks in the life-cycle are
available" on the Ajax.Responders.register() description (p32) but the
list of Responder callbacks (p25) only lists 7 of them (not including

My second concern is that Responder's callback seems to be always
called after the local one (the one defined in the ajax call).

I wanted to implement some kind of "server throwable exceptions",
which basically would allow me to return a JSON object with some
attributes like {"Error":true, "Code":"ExpiredSession"...} which would
be handled by the default Responder, freeing me from having to test
all unexpected things in every Ajax's callback.

The current behavior doesn't allow to do that easily.
I do think to a solution but don't you think that for the sake of
clarity those Responder callback should be renamed from "onXXX" to
"onAfterXXX" since they are called after the actual onXXX callback ?
(and eventually, some "onBeforeXXX" callback could be added (as well
as onSuccess and onFailure).

I am not very happy with the workaround I found, so feel free to give
me some hints to make it better.
Here it is:

function ResponderOnSuccess(localOnSuccess,request,jsonObj)
  if(!jsonObj) jsonObj = { "Error": true, "Code":"Unknown"};
    // process error;

and for using it:
new Ajax.Request('myRequest.php',
    onSuccess: myCB.wrap(ResponderOnSuccess)

or if you prefer:
new Ajax.Request('myRequest.php',
    onSuccess: (function(xrh,json)
      // Process data here

Last minute idea I just had while writing: Do you think I could use
the onCreate's responder to change the onSuccess by the wrapped

Thanks for any hint,
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 
For more options, visit this group at 

Reply via email to