0

有人可以向我解释为什么我不断收到此错误消息:

XMLHttpRequest 无法加载http://mesonet.agron.iastate.edu/iemre/multiday/2013-04-01/2013-04-12/42.54/-96.40/json。来源 ------------ Access-Control-Allow-Origin 不允许。

但我可以使用以下 URL 访问数据:http: //mesonet.agron.iastate.edu/iemre/multiday/2013-04-01/2013-04-12/42.54/-96.40/json

d3.json("http://mesonet.agron.iastate.edu/iemre/multiday/2013-04-01/2013-04-12/42.54/-96.40/json", function(error, json) {
  if (error) return console.warn(error);
  data = json;

这不是使用 d3 加载外部 json 文件的适当方式吗?

4

1 回答 1

0

As @aug posted, this violates the Same Origin Policy. You can read more about it at http://en.wikipedia.org/wiki/Same_origin_policy

The only way that you can get around this issue is if you have control of the JSON file and then you can add "padding" to the file. You can read more about that at http://en.wikipedia.org/wiki/JSONP

于 2013-11-05T19:22:03.097 回答