PHP 开启跨域

1.普通直接开启跨域
function not_region($boolean)
{
    if($boolean){
        header('Access-Control-Allow-Origin:*');
        header( 'Access-Control-Allow-Methods: GET,POST, OPTIONS' );
        header( 'Access-Control-Allow-Headers: Origin,Content-Type, Accept, Authorization, X-Request-With' );
        header( 'Access-Control-Allow-Credentials: true');
    }
}



2.lumen 开跨域
lumen使用 CORS 解决跨域问题


3
.使用console.log 测试跨域:
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://xxx.com');
xhr.send(null);
xhr.onload = function(e) {
    var xhr = e.target;
    console.log(xhr.responseText);
}

 -

原文地址:https://www.cnblogs.com/q1104460935/p/6913138.html