I have an AJAX post
$.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:
$.ajax({
method: "POST",
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.