【发布时间】:2014-07-22 12:28:50
【问题描述】:
我正在使用D3 graphs 构建一些交互式仪表板。我可以使用静态 JSON 集成图形。现在我想从我正在运行的服务器中获取 JSON。我的服务器需要某种基本授权。
添加基本身份验证标头后,我可以在Restclient 中获取 XML 响应。但在 D3 中它不起作用。
我的 D3 是这样的……
d3.json("http://localhost:9001/***/rest/products", function(error, root) {
var node = svg1.selectAll(".node")
.data(bubble.nodes(classes(root))
.filter(function(d) { return !d.children; }))
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
node.append("title")
.text(function(d) { return d.className + ": " + format(d.value); });
node.append("circle")
.attr("r", function(d) { return d.r; })
.style("fill", function(d) { return color(d.packageName); });
node.append("text")
.attr("dy", ".3em")
.style("text-anchor", "middle")
.text(function(d) { return d.className.substring(0, d.r / 3); });
});
它会给出403 Forbidden 错误,因为这里我没有添加Authentication header。
如何在 D3.json 中添加身份验证标头,以便我可以以 JSON 形式访问我的资源而不会出现任何权限被拒绝的问题。
【问题讨论】:
-
你至少应该能够做到
d3.json("http://username:password@localhost:9001/...")。
标签: javascript jquery json rest d3.js