【发布时间】:2019-03-02 20:08:20
【问题描述】:
尝试从 D3 中的同一文件夹加载本地 .json 文件(并将其记录到控制台),但控制台中有两个错误:
d3.v5.js:5908 Fetch API 无法加载 [buildings.json - 文件]。 URL 方案必须是 用于 CORS 请求的“http”或“https”。 json@d3.v5.js:5908(匿名)@ index.html:10
d3.v5.js:5908 Uncaught (in promise) TypeError: Failed to 拿来 在 Object.json (d3.v5.js:5908) 在 index.html:10 json@d3.v5.js:5908(匿名)@index.html:10 Promise.then(异步)(匿名)@index.html:10
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="https://d3js.org/d3.v5.js"></script>
</head>
<body>
<script>
d3.json("buildings.json").then(data => console.log(data))
</script>
</body>
</html>
有人知道原因并有解决办法吗?
【问题讨论】:
-
如果那是您的数据源,请不要使用 d3.json 来获取您的数据