[英]AJAX response is always 405
I have an AJAX post 我有一个AJAX帖子
$.ajax({
type: "POST",
contentType: "application/json",
url: "/rating/save",
data: JSON.stringify(rating),
dataType: "json",
mimeType: "application/json",
success: function (responseData) {
console.log(responseData);
window.location.href = "/welcome"
},
error: function (responseData) {
console.log(responseData);
}
});
Controller 调节器
@Controller
public class RatingController {
........
@RequestMapping(value = "/rating/save",method = RequestMethod.POST)
public ResponseEntity<Object> saveRating(@RequestBody List<RatingDTO> ratingDTO) {
return new ResponseEntity<>(ratingService.save(ratingDTO),HttpStatus.OK);
}
}
Each time that I'm trying to process the response from the controller even if there is no exception I got 每次我试图处理来自控制器的响应,即使我没有例外
status: 405
statusText: "error"
The error says that the method is not allowed, but service from this endpoint works great. 该错误表明该方法不允许,但来自此端点的服务运行良好。
You should set POST via method
attribute: 您应该通过method
属性设置POST:
$.ajax({
method: "POST",
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.