当前位置:网站首页>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();
}
}
即可解决问题
边栏推荐
- [error record] groovy function parameter dynamic type error (guess: groovy.lang.missingmethodexception: no signature of method)
- Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~
- 每日刷题记录 (十四)
- Oracle is sorted by creation time. If the creation time is empty, the record is placed last
- Analyse des risques liés aux liaisons de microservices
- AD637使用笔记
- Form artifact
- Postman核心功能解析-参数化和测试报告
- 如何创建线程
- K210 learning notes (IV) k210 runs multiple models at the same time
猜你喜欢
Livelocks and deadlocks of concurrency control
Talking about MySQL index
点到直线的距离直线的交点及夹角
Index optimization of performance tuning methodology
Wonderful review of the digital Expo | highlight scientific research strength, and Zhongchuang computing power won the digital influence enterprise award
Nacos installation and service registration
Performance monitoring of database tuning solutions
数博会精彩回顾 | 彰显科研实力,中创算力荣获数字化影响力企业奖
Oracle triggers
Technology cloud report won the special contribution award for the 10th anniversary of 2013-2022 of the "cloud Ding Award" of the global cloud computing conference
随机推荐
航海日答题小程序之航海知识竞赛初赛
MySQL actual combat 45 lecture learning (I)
FBO and RBO disappeared in webgpu
Microservice link risk analysis
"Chris Richardson microservices series" uses API gateway to build microservices
Business learning of mall order module
GWT module may need to be (RE) compiled reduce - GWT module may need to be (RE) compiled reduce
The American Championship is about to start. Are you ready?
[groovy] mop meta object protocol and meta programming (Introduction to groovyobject interface | introduction to metaclass | implementation of class methods using groovyobject invokemethod)
The real situation of programmers
Common interview questions of redis factory
Character conversion PTA
Comment développer un plug - in d'applet
Leetcode simple question: find the nearest point with the same X or Y coordinate
Ad637 notes d'utilisation
2022软件测试工程师涨薪攻略,3年如何达到30K
C language knowledge points link
Advantages and disadvantages of the "Chris Richardson microservice series" microservice architecture
如何创建线程
Web3为互联网带来了哪些改变?