2014-07-01 261 views
3

我試圖讓AJAX請求使用下面的代碼下載從S3一個JSON文件:鉻:GET請求取消CORS HTTPS請求

$.ajax({ 
    'type':'GET', 
    'url':this.baseUrl + publicationId + "/document.json", 
    'crossDomain': true, 
    'dataType':'json', 
    'success':function(data) { 
     console.log('got document.json'); 
    } 
}); 

這在Firefox罰款,和它的作品,如果的baseUrl爲http:// < S3-URL >,但如果是https://開頭,之後,Chrome取消有錯誤的請求:

XMLHttpRequest cannot load https ://s3.amazonaws.com/<bucket-name>/<pub-id>/document.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https ://localhost.office.lucidpress.com' is therefore not allowed access.

製作的捲曲度相同的請求,確實有以下標題:「 Access-Control-Allow-Origin:*「。

爲什麼這不適用於Chrome,是否有任何解決方法?

注:我在URL中放置空格以防止它們變成鏈接。

回答

1

Chrome會發送預飛行OPTIONS請求以查看GET是否可以執行。如果你收到什麼標題curl -X OPTIONS -i https://s3.amazonaws.com/<bucket-name>/<pub-id>/document.json?你最有可能需要添加Access-Control-Allow-Headers到你的服務器響應也允許任何額外的頭Chrome會在OPTIONS請求被髮送,即Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept

或者,因爲這是一個HTTPS請求,你的回答可能是Why Chrome cancel CORS OPTION request

+0

那看起來可能是這樣。 S3爲OPTIONS請求提供403。 – Thayne