Javascript Ajax可以';t捕获从ResponseEntity(Spring MVC)对象发送的错误

Javascript Ajax可以';t捕获从ResponseEntity(Spring MVC)对象发送的错误,javascript,jquery,ajax,spring-mvc,web,Javascript,Jquery,Ajax,Spring Mvc,Web,在我的控制器中: return new ResponseEntity<>("Order is Fulfilled Already!", HttpStatus.BAD_REQUEST); 这是我的Ajax代码: $.ajax({ type : "GET", contentType : "application/json; charset=utf-8", url : "/tt/fulfill/

在我的控制器中:

return new ResponseEntity<>("Order is Fulfilled Already!", HttpStatus.BAD_REQUEST);
这是我的Ajax代码:

           $.ajax({
            type : "GET",
            contentType : "application/json; charset=utf-8",
            url : "/tt/fulfill/order/${orderID}",
            dateType : 'json',
            cache: false,
            success: function (data) {
                alert(data.statusCode);
            },

            error: function (data) {
                alert(data.body);
            },
       });
但是,
HttpStatus.BAD_请求被“success”而不是“error”捕获。(它进入了成功区块)。
我有什么遗漏吗

但是,HttpStatus.BAD_请求被“success”捕获,而不是 “错误”

这意味着ajax成功了。在ajax失败时发生

ajax错误函数的执行主要是因为问题


您可以检查此ajax的状态代码

我不知道spring框架,但我相信ajax需要在标题中包含失败状态,而不是主体,才能将其捕获为错误。也许我认为坏的请求是404?我怎样才能真正解决我的问题?
           $.ajax({
            type : "GET",
            contentType : "application/json; charset=utf-8",
            url : "/tt/fulfill/order/${orderID}",
            dateType : 'json',
            cache: false,
            success: function (data) {
                alert(data.statusCode);
            },

            error: function (data) {
                alert(data.body);
            },
       });