Walter,

What I do in those case is:
- Returning my own error code in a JSON's attribute (lets use
myJsonStatus for the example)
- Use AJAX.Responders to override onCreate to wrap the provided
onSuccess into a custom function which checks
responseJSON.myJSONStatus and do appropriate processing if present or
call provided onSuccess handler if it is not.

I only use this for "unrecoverable errors" but I guess you may provide
to your Ajax.Request custom handlers like
onMyPrivateAppStatusUserDidSomethingWrong and call it if your
myJsonStatus is 'UserDidSomethingWrong' (you may of course use
numerical codes, but example is then less funny :o) )

(untested) implementation:

Ajax.Responders.register(
onCreate: function(r) {
  r.options.onSuccess = (r.options.onSuccess||
Prototype.emptyFunction).wrap(function(localCB,xhr,xjs){
    var js = xhr.responseJSON || {myJsonStatus:'MalformedJSON'};
    if(js.myJsonStatus){
      (r.options['onMyPrivateAppStatus'+js.myJsonStatus]||
Prototype.emptyFunction)(xhr,xjs);
    }
    else {
      localCB(xhr,xjs);
    }
  });
});


usage:

new Ajax.Request('myAjaxScript.php',{
  parameters: {'whatever':'is needed here'},
  onSuccess: function () {...},
  onMyPrivateAppStatusUserDidSomethingWrong: function() {...},
  onMyPrivateAppStatusMalformedJSON: function() {...}
});

Eric

On Jul 7, 2:27 pm, Walter Lee Davis <wa...@wdstudio.com> wrote:
> On Jul 7, 2011, at 8:21 AM, T.J. Crowder wrote:
>
> > To my mind, HTTP response codes aren't for application logic
> > signalling. They're for signalling between the browser and server. The
> > correct response to bum data from the user is a 200 with an
> > application-logic-level success/error flag.
>
> Fair enough, but since the onFailure callback only runs if the  
> response code sent back is something other than the 200 range, how  
> would you recommend I send back that failure other than with the  
> status code?
>
> Walter

-- 
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 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to