弹簧控制器:
response.sendError(500, ErrorMessage.DataBaseInsertFailed);
我的 .jsp 页面
complete: function(e, xhr, settings){
var errorMessage = $.parseJSON(e.responseText);
alert(errorMessage);
}
如果我做 e.status,我得到 500
如果我执行 e.resonseText 我会得到整个文本,但是我希望显示我的自定义消息“由于...导致数据库失败”我的警报语句甚至不会触发。如果我这样做alert(xhr)
也不会触发。
以上来自SO中的这个
查看此文档并更改我的签名以匹配文档
complete
Type: Function( jqXHR jqXHR, String textStatus )
A function to be called when the request finishes (after success and error callbacks are executed). The function gets passed two arguments: The jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object and a string categorizing the status of the request ("success", "notmodified", "error", "timeout", "abort", or "parsererror"). As of jQuery 1.5, the complete setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event.