如果我要求我的 jQuery AJAX 请求 Linux Apache Server 一切似乎都很好。如果我请求 Windows XAMPP 服务器,在 Windows 上的某些浏览器中会显示:
"Cross-origin resource sharing check [response verification]
Access denied, Origin: not matching."
我认为两个服务器响应的标头完全相同,所以我不知道问题出在哪里。
有来自 Linux 服务器的请求和响应的标头:
要求:
URL:http://data.chlupac.com/livetime24/index.php/livetime/get_table/livetiming1/0/0?_=1372192293003
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,cs;q=0.6
Cache-Control:max-age=0
Connection:keep-alive
Content-Type:text/plain
Host:data.chlupac.com
Referer:http://data.chlupac.com/livetime24/
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36
X-Requested-With:XMLHttpRequest
Query String Parametersview sourceview URL encoded
_:1372192293003
回复:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Authorization, X-Requested-With, Content-Type, Origin, Accept
Access-Control-Allow-Methods:GET, OPTIONS
Access-Control-Allow-Origin:*
Access-Control-Allow-Origin:data.chlupac.com
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:2508
Content-Type:text/html
Date:Tue, 25 Jun 2013 20:31:31 GMT
Keep-Alive:timeout=15, max=99
Server:Apache/2.2.16 (Debian)
Vary:Accept-Encoding
X-Powered-By:PHP/5.3.3-7+squeeze14
这很好用。
还有我的请求和来自 Windows 服务器的响应:
要求:
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,cs;q=0.6
Connection:keep-alive
Content-Type:text/plain
Host:championchip.cz
Referer:http://championchip.cz/new/livetime24/livetime/index/livetiming2
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36
X-Requested-With:XMLHttpRequest
回复:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Authorization, X-Requested-With, Content-Type, Origin, Accept
Access-Control-Allow-Methods:GET, OPTIONS
Access-Control-Allow-Origin:http://championchip.cz
Connection:Keep-Alive
Content-Type:text/html
Date:Tue, 25 Jun 2013 20:36:27 GMT
Keep-Alive:timeout=5, max=96
Server:Apache/2.2.9 (Win32) DAV/2 mod_ssl/2.2.9 OpenSSL/0.9.8h mod_autoindex_color PHP/5.2.6
Transfer-Encoding:chunked
X-Powered-By:PHP/5.2.6
我在 Access-Control-Allow-Origin 中的主机之前尝试了没有“http://”,但它没有用。
有 Javascript,我正在使用:
$.ajaxSetup({
xhrFields: {
withCredentials: true
}
});
$.support.cors = true;
val_livetime="0";
val_vysledky="0";
val_kategorie="0";
$("#vysledky").change(function () {
val_kategorie="0";
$("#vysledky option:selected").each(function () {
val_vysledky = $(this).val();
});
$.ajax({
url: "<?= site_url('livetime/get_options_kat') ?>/" + val_livetime +"/"+val_vysledky,
contentType: 'text/plain',
cache: false}).done(function(html){
$("#kategorie").html(html);
});
})
.trigger('change');
感谢您的回答。:)