如何获取json的实时数据?

我花了很大一部分时间来研究这个问题。

我正试着获取json的实时数据http://citibikenyc.com/stations/json使用d3.json加载到我网站上的页面上。

试试:

var bike = "http://citibikenyc.com/stations/json";

d3.json(bike, function(error, json) {
console.log(json);
});    

不行,我得到了这个error:

XMLHttpRequest cannot load http://citibikenyc.com/stations/json. Origin http://hochemoche.com is not allowed by Access-Control-Allow-Origin. 

我遗漏了什么吗?在我提交请求时是否会有一些来自网页的限制?如果能在这方面提供任何帮助,我们将不胜感激。我不相信这是来自网站的限制。

eg: http://jehiah.cz/citibikenyc

@Blaklaybul

  1. The Access-Control-Allow-Origin parameter must be set by the JSON source, in this case it is "http://citibikenyc.com/stations/json".
  2. Try to include the CORS parameters in the header of the ajax request you are making. See http://techblog.constantcontact.com/software-development/using-cors-for-cross-domain-ajax-requests/
  3. You can try other alternatives like jsonp etc, again information of which is available in the above link.

If you use Chrome browser, you might also use an extension namely "Allow-Control-Allow-Origin: *". After installing and launching it, I believe it will work.

Hope all thing will be ok!