在我的應用程式中,我建立了從HTTP到HTTPS的AJAX請求。這意味着我需要CORS。是以我添加一些标題和參數到jQuery.ajax并進行測試。在Firefox中,所有功能都可以正常工作,但Chrome中沒有。 Chrome“kill”每個失效請求(OPTIONS)。
jQuery腳本:
$(document).on('click','a.ajax',function(e) {
e.preventDefault();
$.ajax(this.href,{
type: 'GET',dataType: 'json',crossDomain: false,headers: {'X-Requested-With': 'XMLHttpRequest'},xhrFields: {
withCredentials: true
}
});
return false;
});
HTTP轉儲:
> OPTIONS /foo HTTP/1.1
> User-Agent: curl/7.29.0
> Host: local.bar.cz
> Accept: */*
> Access-Control-Request-Headers:accept,origin,x-requested-with
> Access-Control-Request-Method:GET
> Origin:http://local.bar.cz
>
< HTTP/1.1 204
< Server: Nginx/1.2.7
< Date: Wed,27 Feb 2013 15:06:54 GMT
< Content-Type: text/html; charset=utf-8
< Connection: keep-alive
< X-Powered-By: Nette Framework
< X-Frame-Options: SAMEORIGIN
< Access-Control-Allow-Origin: http://local.bar.cz
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Headers: accept,x-requested-with
< Access-Control-Allow-Methods: OPTIONS,GET,POST,HEAD
<
任何人知道為什麼Chrome殺死這個請求?