关于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 


  • 8
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

We_Join

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值