我现在如何在我的 js 文件中通过 ajax 将数据正常传递给 MVc 控制器操作
$.ajax({
type: "POST",
url:url,
data: {
start_date: scheduler.getEvent(id).start_date,
end_date: scheduler.getEvent(id).end_date,
text: scheduler.getEvent(id).text,
userId: userId
},
success:function(result){
if(combo.getActualValue() != null){
getUserEvents(id);
}
else{
$.ajax({
url:"/WebElanceSh/events",
success:function(result){
json = result;
scheduler.parse(json, "json");
}
});
}
}
});
在我的控制器中
@RequestMapping(value = "events/add/", method = RequestMethod.POST)
public void addEvent(@RequestBody String start_date,
@RequestBody String end_date,
@RequestBody String text,
@RequestBody Integer userId){
Event event = new Event(text,start_date,end_date);
if(userId == -1){
TestData.getInstance().AddEvent(-1, event);
}
else {
TestData.getInstance().AddEvent(userId, event);
}
}
但我总是加载资源失败:服务器响应状态为 415(不支持的媒体类型)