gpt4 book ai didi

javascript - 使用 D3 的 XHR/发布请求

转载 作者:搜寻专家 更新时间:2023-11-01 04:57:59 24 4
gpt4 key购买 nike

我正在研究如何使用非常强大的 D3 发出 POST 请求(我完全可以完全推荐用于数据可视化)并找到了 xhr2 branch,D3 的作者目前正在处理 xhr POST 请求(和其他请求)类型)支持。

这似乎是一个全新的功能,因为合并请求是从昨天(2012 年 9 月 18 日)开始的:)而且我很好奇,我已经想尝试一下,使用以下代码序列(我从这个 location )

 d3.text("localhost/test",function(d) { console.log(d)})
.method("POST")
.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
.data("a=1&b=2&c=3");

很遗憾,我收到以下错误消息。

TypeError: 'undefined' is not a function (evaluating 'd3.text("localhost/test",function(d) { console.log(d)}) .method("POST")')

我正在使用 xhr2 分支中的 minified D3 version。有人知道要改变什么吗?

最佳答案

API 仍在开发中。如果你想尝试一下,目前的 API 是这样的:

d3.text("/test")
.header("Content-type", "application/x-www-form-urlencoded")
.post("a=1&b=2&c=3", function(error, text) { console.log(text); });

如果您想要完整的请求对象而不仅仅是 responseText,您也可以直接使用 d3.xhr 而不是 d3.text。

编辑:更新到最新的 API。

关于javascript - 使用 D3 的 XHR/发布请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12493758/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com