You can always use the callback method, and the request will always be in this block. As you know, when the data contains an error and not, this method will work for server-side errors. And you can catch errors on the client side by specifying the last else block.
$.post("test", { ajax: "true", action: "" }).always(function(data){ if (data == "ok"){ //xxx } else if (data == "err"){ //handle server-side errors } else { //handle client-side errors like 404 errors } });
source share