关于ajax已经成功了,却报404的错误的问题

今天遇到了一个很离奇的场景,使用ajax请求后台结果 后台处理成功了页面还报了404错误。

关于ajax已经成功了,却报404的错误的问题

关于ajax已经成功了,却报404的错误的问题

关于ajax已经成功了,却报404的错误的问题


上代码:

JS:


var save = function(){
    $.ajax({
              url: urlMap.saveOrUpdateGroupInfo,
              type: 'post',
              async: false,
              dataType: 'json',
              data: $("#groupInfo").serialize()
        }).done(function(res) {
         console.log(res);
          if(res.success) {
              
            }else{
              bootbox.alert(res.msg);
              
            }
        });
}



  1.  @RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)  
  2.     public ResponseVo saveOrUpdate(String id, String name, String parentId, String parentName, String operate){  
  3.         ResponseVo result = new ResponseVo();  
  4.         GroupInfo info = new GroupInfo();  
  5.         Date now =new Date();  
  6.         info.setUpdateTime(now);  
  7.             try{  
  8.                 if(operate.equals("add")){  
  9.                     info.setParentId(Integer.parseInt(parentId));  
  10.                     info.setName(name);  
  11.                     info.setCreateTime(now);  
  12.                     groupInfoService.addGroup(info);  
  13.                 }else if (operate.equals("edit")) {  
  14.                     info.setId(Integer.parseInt(id));  
  15.                     info.setName(name);  
  16.                     info.setParentId(Integer.parseInt(parentId));  
  17.                     groupInfoService.updateGroup(info);  
  18.                 }else if (operate.equals("delete")) {  
  19.                     groupInfoService.deleteGroup(Integer.parseInt(id));  
  20.                 }  
  21.                 result.setSuccess(true);  
  22.             }catch (Exception e){  
  23.                 log.error("operate group error."+ JsonUtil.toString(info), e);  
  24.                 result.setSuccess(false);  
  25.                 result.setMsg(e.getMessage());  
  26.             }  
  27.         return result;  
  28.     }  
  29. }  



挺奇怪吧?

经分析是请求没有返回状态码,这是因为我用的是SpringMVC框架,前后端使用JSON传递数据,因为返回的是对象,而忘记了添加

@ResponseBody

注解,所以 Spring对我的返回值进行了映射,但是映射结果又对应不到视图,所以返回了404

正常后台代码:


  1. @RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)  
  2.     @ResponseBody