sto affrontando l'errore:AJAX POST a Spring MVC controller non funziona
Failed to load resource: the server responded with a status of 415 (Unsupported Media Type)
AJAX parte del mio codice è il seguente:
$.ajax({
url: '/authentication/editUser',
type: "POST",
contentType: "application/json",
data: JSON.stringify(requestObj), //Stringified JSON Object
success: function(resposeJsonObject) {
//
}
});
E metodo del gestore del controller:
@RequestMapping(value = "/editUser", method = RequestMethod.POST,
headers = {"Content-type=application/json"})
@ResponseBody
public EditUserResponse editUserpost(@RequestBody EditUserRequest editUserRequest) {
System.out.println(editUserRequest);
return new EditUserResponse();
}
Come risolvere l'errore?
Provare a passare il tipo di contenuto nelle intestazioni. –
viene eseguito nella chiamata ajax come contentType: "application/json" –
Sto dicendo di passarlo separatamente nelle intestazioni come 'intestazioni: { 'Accept': 'application/json', 'Content-Type': ' application/json ' }, qualcosa come questo. –