XHR / Post Request using D3

I did research on how to make POST requests using amazingly powerful D3 (which I can fully recommend for visualizing data) and found the xhr2 branch where D3 authors are currently working on xhr POST request (and other types of requests).

This seems to be a new feature, since the merge request from yesterday (September 18, 2012) :) And as I am curious, I already wanted to try using the following code sequence (which I have from this 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"); 

Sorry, I am getting the following error message.

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

I am using a mini version of D3 from the xhr2 branch. Does anyone know what to change?

+4
source share
1 answer

The API is still under development. If you want to try, the current API looks like this:

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

You can also use d3.xhr, not d3.text, if you want to get the full request object, not just responseText.

Edit: Updated to the latest API.

+10
source

Source: https://habr.com/ru/post/1435046/


All Articles