You must create an action map using the statusCode parameter:
$.ajax({ statusCode: { 400: function() { alert('400 status code! user error'); }, 500: function() { alert('500 status code! server error'); } } });
Link (Scroll to: 'statusCode')
EDIT (in response to comments)
If you need to take an action based on the data returned in the response body (which seems strange to me), you will need to use error: instead of statusCode:
error:function (xhr, ajaxOptions, thrownError){ switch (xhr.status) { case 404:
George Cummins Jul 14 '11 at 22:44 2011-07-14 22:44
source share