Yii2 跨域处理

2022-09-09 17:12:22 浏览数 (3)

代码语言:javascript复制
    public function behaviors()
    {
        $behaviors = [
            'corsFilter' => [
                'class' => Cors::className(),
                'cors' => [
                    'Origin' => [],//跨域的域名数组
                    'Access-Control-Request-Method' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],
                    'Access-Control-Request-Headers' => ['*'],
                    'Access-Control-Allow-Origin' => ['*'],
                    'Access-Control-Allow-Credentials' => true,
                    'Access-Control-Max-Age' => 86400,
                    'Access-Control-Expose-Headers' => [],
                ],
            ],
        ];
        return $behaviors;
    }                        

代码语言:javascript复制
$.ajax({
    type: "POST",
    data: {},
    url: wxCheckUrl,
    async: false,
        crossDomain:true,
    success: function(msg) {}
    });

0 人点赞