作者 lihan
1 个管道 的构建 通过 耗费 1 秒

跨域问题

@@ -13,6 +13,19 @@ use think\Db; @@ -13,6 +13,19 @@ use think\Db;
13 class PlaceController extends HomeBaseController 13 class PlaceController extends HomeBaseController
14 { 14 {
15 15
  16 + function _initialize()
  17 + {
  18 + parent::_initialize(); // TODO: Change the autogenerated stub
  19 + header("Access-Control-Allow-Origin: *"); // 允许任意域名发起的跨域请求
  20 + // 指定允许其他域名访问
  21 + header('Access-Control-Allow-Origin:*');
  22 + // 响应类型
  23 + header('Access-Control-Allow-Methods:POST');
  24 + // 响应头设置
  25 + header('Access-Control-Allow-Headers:x-requested-with,content-type');
  26 +
  27 + }
  28 +
16 public function add() 29 public function add()
17 { 30 {
18 $request = request(); 31 $request = request();