2012-04-27 23 views
0

這是我在我的Chrome控制檯中看到的錯誤。nginx,jquery - 在進行POST時獲取訪問控制 - 允許 - 來源錯誤

XMLHttpRequest無法加載{URL}。 Access-Control-Allow-Origin不允許來源{URL}。

我試圖配置我NGINX的CORS:

location/{ 
    if ($http_origin) { 
     add_header Access-Control-Allow-Origin *; 
     add_header Access-Control-Allow-Methods "GET,POST,OPTIONS"; 
    } 

但是,這似乎並沒有幫助。

jQuery的調用看起來是這樣的:

var submissionData = '{"tweet_id":"'+tweet_id+'", "question_id":"'+question_id+'", '+choiceString+', "extra_passback":"'+extra_passback+'"}'; 
$.post("http://ec2[...].amazonaws.com/question/answer/", submissionData, function(data) {console.log("success");}); 

我甚至不能確定問題是否與jQuery或nginx的。

+0

你必須看看[link](http://bionicspirit.com/blog/2011/03/24/cross-domain-requests.html),你在你的根目錄下有沒有crossdomain.xml? – 2012-04-28 22:08:16

回答

3

基於this post,我增加了兩個頭(除了你在上面你的問題中提到的兩個)和它的作品對我來說,使用jQuery JSON跨域請求:

add_header   Access-Control-Allow-Headers Content-Type; 
add_header   Access-Control-Max-Age   86400; 
相關問題