大家好我刚开始使用Javascript而且我想使用d3而且我遇到了一个问题:
XMLHttpRequest cannot load https://blahblah/api/votes. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access.
我的控制台显示了此问题。
附上我的代码:
<!DOCTYPE html>
<html>
<head>
<title>Testbed!</title>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript"></script>
</head>
<body>
<script>
d3.select("body").append("p").text("hi, whats up");
console.log(d3);
d3.json("https://blahblah/api/votes", function(data) {
var canvas = d3.select("body").append("svg")
.attr("width", 500)
.attr("height", 500)
canvas.selectAll("rect")
.data(data) //the data in the bracket is because our function uses the varible data
.enter()
.append("rect")
.attr("width", function(d) { return d; })
.attr("height", 50)
.attr("y", function(d,i) { return i*10; })
.attr("fill", "blue");
canvas.selectAll("text")
.data(data)
.enter()
.append("text")
.attr("fill", "white")
.attr("y", function(d,i) { return i*50; })
.text(function (d) { return d.document_id + 25; })
})
</script>
</body>
</html>
有人可以给我一些关于发生了什么的线索吗?