0

我正在从我的项目中提取一个 json 文件,然后将其作为静态文件写入 javascript 目录中,如下所示:

json_file_path = Rails.root.join("data", "infographics.json")
json_object = JSON.parse(open("http://url/api/infographics/all").read)
File.open(json_file_path, 'w') {|f| f.write(json_object.to_json) }

但是当我从我的开发机器读取这个文件到远程服务器时,我得到一个错误:

Origin http://0.0.0.0:3000 is not allowed by Access-Control-Allow-Origin.

这是 apache 设置还是我在编写时没有正确设置标题?

4

2 回答 2

1

您可以Access-Control-Allow-Origin像这样设置标题:

Header set Access-Control-Allow-Origin *

<Directory>, <Location>, <Files>,<VirtualHost>.htaccess

于 2012-04-21T01:04:26.283 回答
1

这是因为您使用了与您调用它的地址不同的 IP 或域名来访问资源。例如:进入http://localhost:3000并试图访问http://0.0.0.0:3000http://127.0.0.1:3000

于 2012-04-21T01:17:55.760 回答