当前位置:网站首页>thinkphp5.1跨域问题解决
thinkphp5.1跨域问题解决
2022-07-05 22:17:00 【沐言鸭】
新建一个控制器–Cross
php think make:controller api/Cross
阅读官方文档tp5.1跨域可以了解到基本写法
在此控制器里面初始化方法
protected function initialize()
{
parent::initialize(); // TODO: Change the autogenerated stub
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:GET, POST, PATCH, PUT, DELETE');
header('Access-Control-Allow-Headers:Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With');
if (request()->isOptions()){
exit();
}
}
即可解决问题
边栏推荐
- How to quickly experience oneos
- Leetcode simple question: the minimum cost of buying candy at a discount
- 70. Climbing Stairs. Sol
- opencv 判断点在多边形内外
- Leetcode simple question: check whether each row and column contain all integers
- The real situation of programmers
- Ad637 notes d'utilisation
- "Chris Richardson microservices series" uses API gateway to build microservices
- Microservice link risk analysis
- When the industrial Internet era is truly mature, we will look at the emergence of a series of new industrial giants
猜你喜欢
MySQL服务莫名宕机的解决方案
What changes has Web3 brought to the Internet?
Daily question brushing record (XIV)
boundary IoU 的计算方式
Practice: fabric user certificate revocation operation process
The real situation of programmers
2022-07-05: given an array, you want to query the maximum value in any range at any time. If it is only established according to the initial array and has not been modified in the future, the RMQ meth
Performance monitoring of database tuning solutions
Solutions for unexplained downtime of MySQL services
Web3为互联网带来了哪些改变?
随机推荐
509. Fibonacci Number. Sol
Win11运行cmd提示“请求的操作需要提升”的解决方法
Unique occurrence times of leetcode simple questions
Blocking of concurrency control
1.3 years of work experience, double non naked resignation agency face-to-face experience [already employed]
How to add new fields to mongodb with code (all)
2022软件测试工程师涨薪攻略,3年如何达到30K
opencv 判断点在多边形内外
C language knowledge points link
科技云报道:算力网络,还需跨越几道坎?
Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server
How to quickly experience oneos
Decorator learning 01
点到直线的距离直线的交点及夹角
What if win11 is missing a DLL file? Win11 system cannot find DLL file repair method
MySQL actual combat 45 lecture learning (I)
Type of fault
Overriding equals() & hashCode() in sub classes … considering super fields
Character conversion PTA