當我運行下面的代碼: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