thinkphp5.0 请求伪装PUT和DELETE
作者:互联网
对应手册:点击查看
由于一些低版本的浏览器不支持PUT请求和DELETE请求,为了兼容可以使用请求伪装。
请求类型伪装,可以在POST
表单里面提交_method
变量,传入需要伪装的请求类型
ajax请求伪装:
<input type="button" id="post_to_put" value="伪装put"> <input type="button" id="post_to_delete" value="伪装delete"> <script> $(function(){ $('#post_to_put').click(function(){ $.ajax({ "url":"/news/33", "type":"post", "data":"_method=put", "dataType":"json", "success":function(res){ console.log(res); } }); }); $('#post_to_delete').click(function(){ $.ajax({ "url":"/news/33", "type":"get", "data":"_method=delete", "dataType":"json", "success":function(res){ console.log(res); } }); }); }) </script>
form表单伪装成PUT请求:
<form method="post" action=""> <input type="text" name="name" value="Hello"> <input type="hidden" name="_method" value="PUT" > <input type="submit" value="提交"> </form>
标签:function,请求,res,PUT,thinkphp5.0,伪装,post,method,DELETE 来源: https://www.cnblogs.com/dazahui/p/14403845.html