我在很多服务器上都有网站。但是在每台服务器上,我使用一个网站通过ajax跨域请求。在php文件中,允许访问的位置我有:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
在Javascript中,我有类似的东西:
$.getJSON('http://example.com/request.php?check=' + request, function(data) {
...
在服务器上,它工作正常,但是当我在localhost上时,我会在我的控制台中看到它:
XMLHttpRequest cannot load [request]. A wildcard '*' cannot be used in the
'Access-Control-Allow-Origin' header when the credentials flag is true.
Origin 'http://localhost:8102' is therefore not allowed access.