加载Javascript时出现问题
大家好,我刚开始使用Javascript,我想使用d3,但我已经遇到了一个问题:加载Javascript时出现问题,javascript,d3.js,Javascript,D3.js,大家好,我刚开始使用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. 这个问题显示在我的控
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>
有人能给我一些关于发生了什么的线索吗?读一下:你不能对不同域上的资源进行Ajax调用,除非它们给你访问权限,或者除非服务支持JSONP,而你使用的是甚至没有进行Ajax调用的资源,它使用的是标记。我建议您仔细阅读您尝试使用的特定API如何支持跨域访问。请参阅以下问题之一: