我正在尝试提出一个简单的跨域请求,而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之外的所有浏览器。有人能帮忙吗?
Accept application/json, text/plain, */*
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Content-Length 35
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Host [url]
Origin [url]
Referer [referrer url]
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:30.0) Gecko/20100101 Firefox/30.0
错误: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at [url]. This can be fixed by moving the resource to the same domain or enabling CORS. [url]
mozSystem
仅打包了firefox-os应用程序的常规网站不支持此功能,因此请删除该选项。