您的位置:首页 > 产品设计 > UI/UE

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

2016-11-29 21:24 696 查看
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。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐