我正在尝试发出一个简单的跨域请求,而 Firefox 始终使用此错误阻止它:
跨域请求被阻止:同源策略不允许读取 [url] 处的远程资源。这可以通过将资源移动到同一域或启用 CORS 来解决。[网址]
它在 Chrome 和 Safari 中运行良好。
据我所知,我已经在我的 PHP 上设置了所有正确的标头以允许它工作。这是我的服务器响应的内容
HTTP/1.1 200 OK
Date: Mon, 23 Jun 2014 17:15:20 GMT
Server: Apache/2.2.22 (Debian)
X-Powered-By: PHP/5.4.4-14+deb7u8
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type
Access-Control-Request-Headers: X-Requested-With, accept, content-type
Vary: Accept-Encoding
Content-Length: 186
Content-Type: text/html
我尝试过使用 Angular、jQuery 和一个基本的 XMLHTTPRequest 对象,如下所示:
var data = "id=1234"
var request = new XMLHttpRequest({mozSystem: true})
request.onload = onSuccess;
request.open('GET', 'https://myurl.com' + '?' + data, true)
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
request.send()
...它适用于除 Firefox 之外的所有浏览器。有人能帮忙吗?