Fed*_*pi 3 javascript ajax jquery controller delete-record
我正在尝试使用 Ajax 执行 DELETE 请求,但它不起作用,我收到内部错误,但我看不到问题,你能帮助我吗?
这是javascript的部分代码:
$.ajax({
url: 'http://localhost:8080/actors/remover',
type: 'DELETE',
data: JSON.stringify(movie),
traditional:true,
dataType: 'json',
success: function(result) {...},
error: function(result){...}
});
Run Code Online (Sandbox Code Playgroud)
这是我的控制器的代码:
@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
Run Code Online (Sandbox Code Playgroud)
我在你的代码中看到的问题:
dataType:'json'如果您获得 json 对象形式的响应,则使用。json根本不进行生产,但有一个boolean.contentType:'application/json'.traditional:true。所以我建议你使用这个:
$.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){...}
});
Run Code Online (Sandbox Code Playgroud)