首页> 实战笔录 >PHP开发笔记 >ThinkPHP ThinkPHP
Tp6 $request->isAjax()不能验证axios提交的请求
作者:小萝卜 2024-04-15 【 TP6 Vue3 】 浏览 1127
简介Tp6 $request->isAjax()不能验证axios提交的请求,需要在请求头部header中添加对应参数XMLHttpRequest
Tp6 $request->isAjax()不能验证axios提交的请求
原因:axios 请求头中没有带 X-Requested-With 这个参数。
解决办法:
给请求头添加 X-Requested-With 这个参数,参数值为 XMLHttpRequest
// 以 axios 为例
this.$axios.get('http://yourdomain.com/api/getMenus',
{
headers: {'X-Requested-With': 'XMLHttpRequest'}
}).then((res)=>{
// console.log(res.data);
})
很赞哦! (0)
相关文章
- ThinkPHP3.2和5.0的区别
- TP5 关联模型使用(嵌套关联、动态排序以及隐藏字段)
- TP6上传图片验证时报错think\\Validate::check() must be of the type array
- TP6文件上传详解
- TP5 添加平铺水印并设置水印之间的间距
- thinkphp utf8中文排序,根据汉字拼音首字母排序
- TP3.2使用join查询实例以及注意事项
- tp6表单验证提交之后报错Call to a member function set() on null
- tp5 致命错误: Class 'think\route' not found
- TP6权限管理 Auth库的使用