XMLHttpRequest Access-Control-Allow-Origin最初几次失败

时间:2013-01-10 12:56:16

标签: javascript http-headers cross-domain

我使用此代码大约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)

请帮助我!

0 个答案:

没有答案