当前位置:网站首页>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();
}
}
即可解决问题
边栏推荐
- Matlab draws a cute fat doll
- Technology cloud report: how many hurdles does the computing power network need to cross?
- MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server
- Understand the basic concept of datastore in Android kotlin and why SharedPreferences should be stopped in Android
- Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~
- [groovy] mop meta object protocol and meta programming (execute groovy methods through metamethod invoke)
- Recovery technology with checkpoints
- Wonderful review of the digital Expo | highlight scientific research strength, and Zhongchuang computing power won the digital influence enterprise award
- A long's perception
- Decorator learning 01
猜你喜欢

How to quickly experience oneos

Bitbucket installation configuration

Getting started with microservices (resttemplate, Eureka, Nacos, feign, gateway)

K210 learning notes (IV) k210 runs multiple models at the same time

Decorator learning 01

A trip to Suzhou during the Dragon Boat Festival holiday

MySQL服务莫名宕机的解决方案

The simple problem of leetcode is to split a string into several groups of length K

数博会精彩回顾 | 彰显科研实力,中创算力荣获数字化影响力企业奖

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
随机推荐
Lightweight dynamic monitorable thread pool based on configuration center - dynamictp
Common interview questions of redis factory
Storage optimization of performance tuning methodology
如何创建线程
Ad637 notes d'utilisation
每日刷题记录 (十四)
Pinctrl subsystem and GPIO subsystem
Go语言学习教程(十五)
Summary of concurrency control
Advantages and disadvantages of the "Chris Richardson microservice series" microservice architecture
实战:fabric 用户证书吊销操作流程
Postman核心功能解析-参数化和测试报告
Depth first DFS and breadth first BFS -- traversing adjacency tables
90后测试员:“入职阿里,这一次,我决定不在跳槽了”
Sentinel production environment practice (I)
Metaverse Ape猿界应邀出席2022·粤港澳大湾区元宇宙和web3.0主题峰会,分享猿界在Web3时代从技术到应用的文明进化历程
The American Championship is about to start. Are you ready?
Microservice link risk analysis
Granularity of blocking of concurrency control
Oracle is sorted by creation time. If the creation time is empty, the record is placed last