目前是否不支持通过请求提交多部分表单数据?
我了解如何使用 d3.json().post() 执行 POST here ,但我想使用 POST 通过 multipart/form-data 向 API 提交参数。
我找不到任何关于如何最好地做到这一点的资源,这似乎很奇怪;我最接近的是https://github.com/mbostock/d3/issues/929和 https://github.com/mbostock/d3/wiki/Requests但这些并没有真正涵盖多部分形式。
我在 d3.v3.js 中找不到 #929 中描述的功能的未记录部分是否允许使用多部分表单?是否有人目前正在研究或对此问题感兴趣?
最佳答案
成功的多部分帖子需要三个步骤。
Content-type: application/x-www-form-urlencoded
然后将其作为 POST 数据发送。
这些都不是特定于 d3 的,但我想我会给出我的答案和一些示例代码,因为我来到这里。
示例代码:
var xhr = d3.xhr(post_url)
.header("Content-type", "application/x-www-form-urlencoded");
xhr.post("arg1=" + encodeURIComponent(arg1) + "&arg2=" + encodeURIComponent(arg2),
function(error, result) {
if(error)
throw new Error(error);
read_paths.data(JSON.parse(result.responseText));
});
关于json - 使用 d3.json()/d3.xhr() 的多部分发布请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13887386/