How to solve Cross-domain problems through Global Middleware in thinkphp6
This article will explain in detail how thinkphp6 solves cross-domain problems through global middleware. The content of the article is of high quality, so Xiaobian shares it with you as a reference. I hope you have a certain understanding of relevant knowledge after reading this article.
TP6 solves cross-domain problems through global middleware
Tp6 official website provides cross-domain resolution method, when I directly use can not be used. (Maybe I'm using the wrong posture.)
The frontend sends ajax requests in Hbuildert, which occurs across domains.
Get request: can be resolved through background settings. 'Access-Control-Allow-Origin: *'。post request: An OPTIONS request occurs. Add a header to the ajax request. header:{ 'Content-Type':'application/x-www-form-urlencoded'} Define middleware