How do I post parameter on d3.json?

后端 未结 5 590
無奈伤痛
無奈伤痛 2020-12-08 10:50

I\'m using d3.json to get a dynamic data.

d3.json(\"/myweb/totalQtyService.do\", function(json) {

    drawChart(json);
});

How do I post

5条回答
  •  醉话见心
    2020-12-08 11:47

    If you want to make a request like an HTML form (using query parameters), then you would do:

    d3.request("/path/to/resource")
    .header("X-Requested-With", "XMLHttpRequest")
    .header("Content-Type", "application/x-www-form-urlencoded")
    .post("a=2&b=3", callback);
    

    See the docs here: d3-request docs

    If you want to convert a simple object to a query parameter string, then you can use the following function:

    function obj2Params(params){
      var str = "";
      var amp = "";
      for(var p in params){
        if(params.hasOwnProperty(p)) {
            str += amp + encodeURIComponent(p) + "=" + encodeURIComponent(params[p]);
            amp = "&";
        }
      }
      return str;
    }
    

提交回复
热议问题