我在向Java控制器发送JSON数据时遇到问题。
我在JSP文件中有以下方法:
$.ajax({
type: "POST",
url: "/addPerson.html",
data: JSON.stringify({
aanvraag_id : chosenAanvraagId,
sharingbox_id : chosenSharingboxId
}),
contentType: 'application/json',
success: function(data) {
alert("de operatie is uitgevoerd");
}
});
这是我的控制器:
@RequestMapping(value = { "/addPerson" }, method = RequestMethod.POST , headers = {"Content-type=application/json"})
@ResponseBody
public JsonResponse addPerson(@RequestBody Person person) {
System.out.println(person.toString());
return new JsonResponse("OK", "");
}
当我调用ajax方法时,我得到一个错误
Status Code 405 : "POST method not found."
有人知道这里的问题是什么吗?
提前感谢!
您必须更改JSP 中的url
$.ajax({
type: "POST",
url: "/addPerson.html", // you can't write .html here, it should just be "/addPerson"
data: JSON.stringify({
aanvraag_id : chosenAanvraagId,
sharingbox_id : chosenSharingboxId
}),
contentType: 'application/json',
success: function(data) {
alert("de operatie is uitgevoerd");
}
});