2

我使用此代码大约 20 次从我的外部服务器加载图像:

var xhr = new XMLHttpRequest();
xhr.open('GET', uri, true); //uri is the image link
xhr.responseType = 'blob';
xhr.onload = function(event){

在存储这些图像的目录中,我放置了一个包含以下内容的 htaccess 文件:

Header set Access-Control-Allow-Origin "*"

除了要检索的前 4 张图像外,此代码工作正常。我收到以下错误:

Origin http://localhost is not allowed by Access-Control-Allow-Origin.

这怎么可能?图像之间没有真正的区别,代码没有改变?:\

这是我在 Chrome 中看到的失败图像:

Request URL:http://www.ardennenbed.nl/sitemanager/fotos/1329589074.jpg
Request Headers
Origin:http://localhost
Referer:http://localhost/app/www/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11

这是我在 Chrome 中看到的工作图像:

Request URL:http://www.ardennenbed.nl/sitemanager/fotos/1280247085.gif
Request Method:GET
Status Code:200 OK (from cache)

Request Headers
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
DNT:1
Host:www.ardennenbed.nl
Origin:http://localhost
Referer:http://localhost/app/www/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11

Response Headers
Accept-Ranges:bytes
Access-Control-Allow-Origin:*
Connection:close
Content-Length:8486
Content-Type:image/gif
Date:Thu, 10 Jan 2013 12:19:20 GMT
ETag:"8192d2-2126-eb0e53c0"
Last-Modified:Wed, 09 Jan 2013 18:06:15 GMT
Server:Apache/2.2.3 (CentOS)

请帮我!

4

0 回答 0