I'm trying to do a DELETE request with Ajax, but it doesn't function,I receive an internal error, but i can't see the problem, can you help me?
this is the partial code of javascript:
$.ajax({
url: 'http://localhost:8080/actors/remover',
type: 'DELETE',
data: JSON.stringify(movie),
traditional:true,
dataType: 'json',
success: function(result) {...},
error: function(result){...}
});
and here the code of my controller:
@RequestMapping(value = "/actors/remover", method = RequestMethod.DELETE)//TODO, elimina un attore dal db
public boolean remove(@PathVariable("movie") int movie) {
System.out.println("Attori da cancellare");
serv.deleteActors(movie);
return true;
}//remove
Problems i see in your code:
dataType:'json'
is used if you get your response as a json object.json
at all but there is a boolean
.contentType:'application/json'
.traditional:true
.So i suggest you to use this:
$.ajax({
url: 'http://localhost:8080/actors/remover',
type: 'DELETE',
data: {movie:movie}, //<-----this should be an object.
contentType:'application/json', // <---add this
dataType: 'text', // <---update this
success: function(result) {...},
error: function(result){...}
});