我有一个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
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);
}
}
每次我尝试处理来自控制器的响应,即使我没有异常也
status: 405
statusText: "error"
该错误表明不允许使用该方法,但是从此端点进行的服务效果很好。
答案 0 :(得分:0)
您应该通过method
属性设置POST:
$.ajax({
method: "POST",
...