Failed to load resource: the server responsed with a status of 400 (Bad Request)

ajax请求失败:Failed to load resource: the server responsed with a status of 400 (Bad Request)


一般情况下,造成这个错误的原因有两个: 1. 请求url错误; 2. 前后台数据格式不匹配。


遇到这个问题,首先检查ajax请求url是否正确,前台ajax请求的url与后台配置是否一致

$.ajax({
        url: SUBSYSTEM_APP_NAME + "reportsetting/saveReportSetting",
        ......
});


后台接收请求:

@RequestMapping(value = "saveReportSetting", method = RequestMethod.POST)

如果url配置正确,那么就应该检查前台传递数据格式与后台接收数据的格式是否一致

$.ajax({   
      url: SUBSYSTEM_APP_NAME + "reportsetting/saveReportSetting",
      ...
      data: JSON.stringify(getAllData()),
      ...
});

var getAllData = function () {

    return {
        id: $idHidden.val(),
        name: $name.val(),
        reportTemplate: {id: $reportTemplate.val()},
        active: true,
        weeklyGenerationTime: $weeklyGenerationTime.val(),
        startTime: $startTime.val(),
        endTime: $endTime.val(),
        reportStatisticsType: $reportStatisticsType.val(),
        fileType: $fileType.val(),
        parametersMap: getParameters(),
        sender: $sender.val(),
        password: $password.val(),
        contacts: getContactIds($contactsPeopleTable)
    };
}; 

@RequestMapping(value = "saveReportSetting", method = RequestMethod.POST)
@ResponseBody
public JsonResult saveReportSetting(SessionInfo sessionInfo, @RequestBody ReportSetting reportSetting)
            throws IOException 

上述代码表示getAllData这个函数返回的数据结构与ReportSetting的数据结构应匹配。当修改某个model类之后,需要检查涉及到的数据结构是否要做相应的更改。

除此之外,当你在某个model类中新加属性之后,要为其添加getter和setter,并且该类必须要有一个default constructor。



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值