当我运行下面的代码:Access-Control-Allow-Origin不允许Origin null。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3 Demo: GeoJSON</title>
<script type="text/javascript" src="http://localhost/webserver/d3/d3.js"></script>
<style type="text/css">
/* No style rules here yet */
</style>
</head>
<body>
<script type="text/javascript">
//Width and height
var w = 500;
var h = 300;
//Define default path generator
var path = d3.geo.path();
//Create SVG element
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
//Load in GeoJSON data
d3.json("http://localhost/webserver/us-states.json", function(json) {
//Bind data and create one path per GeoJSON feature
svg.selectAll("path")
.data(json.features)
.enter()
.append("path")
.attr("d", path);
});
</script>
</body>
</html>
我得到以下错误:
XMLHttpRequest cannot load http://localhost/webserver/us-states.json. Origin null is not allowed by Access-Control-Allow-Origin.
这是怎么回事错在这里,我如何解决呢? 我正在关注Scott Murray的书,直到我开始使用json时,我在web服务器上访问文件时都没有问题。
我自己找到了解决方案。 Chrome中的--disable-web-security为我完成了这项工作。 – csnake 2013-03-17 17:06:47
这不是一个长期的解决方案 - 更好地查看CORS并发送正确的访问控制允许起始标题 – imrane 2013-03-17 22:50:38
您对这个imrane有什么意义? – csnake 2013-03-19 19:01:44