Inside my ajax call, if an error is received, I have a warning:
$.ajax({ url: "myUrl", type: 'POST', dataType : "text", data : ({ json : myJson }), success : function(data) { alert('success'); }, error : function() { alert ('error'); }
Inside java, you can send back to cause an error callback in jquery if an exception is thrown. So something like:
try { PrintWriter out = resourceResponse.getWriter(); out.println("success"); out.close(); } catch (Exception e) { PrintWriter out = resourceResponse.getWriter(); out.println("error"); out.close(); }
ie, instead of printing an "error" in the response, the "error" callback is called inside jQuery code.
source share