PUT,DELETE请求

2019-03-18  本文已影响0人  寂静的春天1988

ajax发送put 和 delete 请求时,需要传递参数,如果参数在url地址栏上,则可以正常使用,

如果在 data:中需要传递参数,(浏览器会使用表单提交的方式进行提交) 则需要注意此时应作如下修改:

  1. 请求方式设置为 type:"post",
  2. 在data中加入 __method:"DELETE",或者 _method:"PUT" 参数 ,
    3.后台的controller 仍为对应的DELETE 请求
@@DeleteMapping(value="/answer/{answerId}")
public ResponseResult deleteAnswer(@PathVariable("answerId")int answerId){

}

4、前端代码

  $.ajax({
    url:"http://localhost:8888/answer/"+answerId,
    type:"POST",
    data:{_method:"DELETE", id:issueId,userId:userId},
    dataType:"json",
    success:function(result){
        }
                            
   }

参考链接:https://blog.csdn.net/liuyuanjiang109/article/details/78972644

上一篇 下一篇

猜你喜欢

热点阅读