d3.js - How do I post parameter on d3.json? -
i'm using d3.json dynamic data.
d3.json("/myweb/totalqtyservice.do", function(json) { drawchart(json); });
how post parameter on d3.json? i.e.
data : { year: "2012", customer: "type1“ }
any thought pass parameter on post? not url parameter /myweb/totalqtyservice.do?year=2012&customer=type1
i tried such below, couldn't create work. because info construction different
d3.json => [object, object, object, object]
$.ajax => {entity_name: "activa"entity_tar_val: 350entity_val: 400level: 1_proto_: object},...
$.ajax({ type: "post", url: url, // parameter here info : {year: "2012", customer: "type1“}, success: function(json){ // console.log(json); **drawchart(json);** } , error:function (request, err, ex) { } });
note: reply applies older version of d3.json, see joshuataylor's comment below.
d3.json convenience method wrapping d3.xhr; it's hardwired create requests.
if want post can utilize d3.xhr directly.
something this:
d3.xhr(url) .header("content-type", "application/json") .post( json.stringify({year: "2012", customer: "type1"}), function(err, rawdata){ var info = json.parse(rawdata); console.log("got response", data); } );
because no callback specified in creation of request object it's not sent immediately. 1 time received json response can parsed in standard javascript way i.e. json.parse(data)
documentation d3.xhr here.
d3.js
No comments:
Post a Comment