Yii2 跨域处理

代码语言: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) {}
});</code></pre></div></div>