我一直在尝试创建一个删除端点,以便可以执行该操作。但是,我的ajax并没有进入rest端点,而是跳到调用的error子句!
下面是我的ajax调用的样子:
$('#datatable_col_reorder').on('click', '#tableDeleteButton', function() {
var selectedId = $(this).closest("tr").find('td:first').text();
$.ajax({
type: 'delete',
url: '/delete/profile/' + selectedId,
success: function(){
alert('success');
},
error: function(){
alert('error');
}
});
});下面是我的java rest端点:
@RequestMapping(value = "/delete/profile/{id}", method = RequestMethod.DELETE)
private ResponseEntity<?> deleteProfile(@PathParam("id") String id) {
System.out.println("id");
return ResponseEntity.ok().build();
}我尝试过各种不同的请求-在url中传递id或者作为数据字段,我在delete方法中尝试了不同的anotations。提前感谢您的帮助!
发布于 2019-07-21 22:32:15
文档中提到了错误回调: Type: Function( jqXHR jqXHR,String textStatus,String errorThrown )
因此,您可以通过警告/记录传递的参数来查看确切的错误。然后,回调将如下所示:
error: function(xhr, status, err){
console.log(xhr, status, err);
}问题不在注解中吗?
@RequestMapping(value = "/delete/profile/{id}", method = RequestMethod.GET)method = RequestMethod.GET应为method = RequestMethod.DELETE
https://stackoverflow.com/questions/57134069
复制相似问题