[英]strange behavior of request methods while ajax request
我的控制器中有這種方法
@Controller
@RequestMapping ("/admin/users")
public class AdminUserController {
..
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public @ResponseBody boolean deleteUser(@PathVariable("id") int id,
HttpServletResponse response) {
..
}
..
}
這是ajax請求
$.ajax({
url: '/admin/users/'+id,
type: 'delete',
success: function(data){
console.log(data);
},
error: function(e){
console.log(e);
}
});
當我發送該請求時,它失敗了,我得到405。當我查看響應頭時,我看到了這個Allow:"GET"
。
好。 我在ajax請求中將“刪除”更改為“獲取”,但隨后我得到響應Allow:"DELETE"
..
可以是什么?
我認為您的服務器安全配置不允許使用DELETE操作,基本上是標頭:
ALLOW: GET
建議您嘗試使用GET請求,但是由於您指定了
method = RequestMethod.DELETE
拒絕該方法的GET調用。
您應該將method = RequestMethod.DELETE
更改為method = RequestMethod.GET
並發出HTTP GET請求。
讓我知道是否有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.