Q:

Ajax.beginform callback properties , can not understand the differences

I read an online document that describes the Ajax.Beginform callback properties  , as follow:-

OnBegin (in jquert it is  beforeSend):- Called immediately prior to the request being sent
OnComplete (in jQuery it is complete):- Called if the request is successful
OnFailure (in jQuery it is error):- Called if the request fails
OnSuccess (in jquery it is success):- Called when the request has completed, irrespective of whether the request succeeded or failed

now i can not understand what is meant by "Called when the request has completed, irrespective of whether the request succeeded or failed". let take the following examples:-

now if i am returning http 401 error from my application , which one script will be called , i assume the OnFailure ?, or since i am returning a result the onsuccess will be called instead?
and if an UN-handeled exception is raised , then i assume that the OnFailure will be called, but will the OnComplete fire also ?

Thanks
Thanks 

A:

There will always be a succession of 3 callbacks, assuming the server sends a response back (404, 500, 200, 302, etc.). The OnBegin callback is the first to get called. The request then gets sent and the server sends back an acknowledgement. If the request was successful, OnSuccess gets called; if not, OnFailure gets called. After either one of OnSuccess or OnFailure finishes executing, the OnComplete callback will be called.
You can "visualize" it this way:
          |--success -> OnSuccess() -->|
OnBegin-->                              >--> OnComplete
          |--error   -> OnFailure() -->|

------------time line-------------------------->

Of course, the success/error status needs to get back to the client first.

