Syncronize the order of variables returned by $.ajax.fail(), $.ajax.done(), and $.ajax.always()

Syncronize the order of variables returned by $.ajax.fail(), $.ajax.done(), and $.ajax.always()

1) Syncronize the order of variables returned by $.ajax.fail(), $.ajax.done(), and $.ajax.always().
- the reason for this is mostly to do with using the .always() callback. It's hard to tell when to treat it as a success vs a failure.  There should always be a variable that contains the response from the server because even in a failure the response is useful for debugging. 

2) The jqXHR object should contain a Boolean property that shows weather the response would invoke fail() vs done().  This is so if you are in .always(), then you can tell how it was treated.

3) Regardless of whether the ajax request is a success or failure, the jqXHR object should receive a .responseJSON (when detected as JSON through headers or 'dataType') if it can't be properly decoded its value should be null.

Ultimately I feel that the use of .fail(), .done() cause me to lose control of the process flow and bloat the code with duplicate lines that need to be placed in both functions.  Something like the following is much more flexible because you have complete control of order of operations, and it's still simple to use.

  1. $.ajax({
  2.       ....
  3. })
  4. .always(function () (serverResponse, jqXHR) {
  5.       functionIUseAlwaysBefore() ;
  6.       $('#container').html(serverResponse) ;
  7.       if (jqXHR.triggeredDone()) {
  8.             alert('success') ;
  9.       }
  10.       else {
  11.             alert('failed') ;
  12.       }
  13.       functionIUseAlwaysAfter() ;
  14. }) ;
OR for JSON



  1. $.ajax({
  2.       ....
  3. })
  4. .always(function () (serverResponse, jqXHR) {
  5.       functionIUseAlwaysBefore() ;
  6.       if (!serverResponse) {// or jqXHR.responseJSON
  7.             alert('Server returned bad data') ;
  8.       }
  9.       else {
  10.             // process my JSON object 'serverResponse'
  11.       }
  12.       functionIUseAlwaysAfter() ;
  13. }) ;

But since the order of variables returned by always() isn't consistent, its hard to determine what when to do what again bloating the code.