我在 Apache 中启用了 CORS,以下是我在加载网站时看到的标题:
HTTP/1.1 200 OK
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *
Cache-Control: no-cache, must-revalidate, max-age=0, max-age=0, no-cache
Content-Encoding: gzip
Content-Type: text/html; charset=UTF-8
Date: Wed, 20 Aug 2014 17:05:00 GMT
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Link: <http://test.example.com/?p=7>; rel=shortlink
Pragma: no-cache
Server: Apache
Vary: Accept-Encoding
X-Frame-Options: SAMEORIGIN
X-Mod-Pagespeed: 1.7.30.4-
X-Pingback: http://test.example.com/xmlrpc.php
X-Powered-By: PHP/5.4.28
Content-Length: 6757
Connection: keep-alive
但是,当我重新加载页面时,我收到以下 JS 错误:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://api.example.com/?x=1. This can be fixed by moving the resource to the same domain or enabling CORS.
任何想法为什么这会失败?我正在尝试从 test.example.com 访问 api.example.com
我必须将配置添加到我从中请求数据的服务器中。