In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In view of how to solve the cross-domain problem in ThinkPHP 5.1.37, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
1. Check out the ThinkPHP documentation for an example:
Route::get ('new/:id',' News/read')-> ext ('html')-> allowCrossDomain ()
You only need to add allowCrossDomain () to the end of the route to realize the cross-domain request, so I added-> allowCrossDomain () after each route that requires cross-domain access, and the general cross-domain problem is solved. But some routes still fail across domains?
Another question.
two。 After Baidu search, it is found that the reason is that the front-end AJAX request usually needs to carry token verification, so it also needs to add token to Access-Control-Allow-Headers.
An example of a document is:
Route::get ('new/:id',' News/read')-> ext ('html')-> header (' Access-Control-Allow-Origin','thinkphp.cn')-> header ('Access-Control-Allow-Credentials',' true')-> allowCrossDomain ()
Add-> header ('Access-Control-Allow-Headers','token')-> allowCrossDomain () as above; the code is as follows:
Route::get ('your route',' News/read')-> header ('Access-Control-Allow-Headers',' token')-> allowCrossDomain (); this is the answer to the question about how to solve the cross-domain problem in ThinkPHP 5.1.37. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.