美文网首页
PUT,DELETE请求

PUT,DELETE请求

作者: 寂静的春天1988 | 来源:发表于2019-03-18 18:18 被阅读0次

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

相关文章

网友评论

      本文标题:PUT,DELETE请求

      本文链接:https://www.haomeiwen.com/subject/dsmbmqtx.html