javascript - 使用 API key 加载 D3 Url

标签 javascript json d3.js

我正在尝试从 URL“https://data.raleighnc.gov/resource/5ccj-g2ps.json”加载数据集,但它需要 API key 。我在 D3 或 Jquery 方面没有运气。

我该如何做才能加载 Json 格式的数据集?

我有以下内容:

$.ajax({
url: "https://data.raleighnc.gov/resource/xce4-kemu.json",
type: "GET",
data: {
  "$limit" : 5000,
  "$$app_token" : "YOURAPPTOKENHERE"
}
}).done(data) {
alert("Retrieved " + data.length + " records from the dataset!");
console.log(data);
});

它说我放错了一个“{”,但我不知道在哪里。

最佳答案

你的代码中有很多错误......

$.ajax({
    url: "https://data.raleighnc.gov/resource/xce4-kemu.json", // didn't you want to get another URL??!?
    type: "GET",
    dataType: "json",
    data: {
      "$limit" : 5000, // Does the API require the dollar signs? Looks weird.
      "$$app_token" : "YOURAPPTOKENHERE" // Did you actually replace with your API key?
    },
    success: (data) => {
        alert("Retrieved " + data.length + " records from the dataset!");
        console.log(data);
    },
    error: (xhr, textStatus, errorThrown) => {
        // error
    }
});

应该可以工作。

关于javascript - 使用 API key 加载 D3 Url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40210251/

相关文章:

javascript - 本地存储和 Internet Explorer 9 冒险

javascript - 使用动态导入时将 Webpack block url 作为字符串获取

json - 如何使用 Go 从 JSON 文件中读取一个值

javascript - d3.js 线图错误移动(向右)

javascript - Electron ipc使用远程网站?

javascript - 如何阻止 JavaScript 函数返回值

python - 为什么 Python 的 json.dumps 拒绝序列化我的对象中的字符串?

json - 如何通过 Linux 命令删除 JSON 文件中的对象

javascript - 如何在D3.js中设置节点和其他svg元素之间的碰撞

d3.js - d3 水平条形图,背景为 100%