2017-03-22 3 views
0

私は動的APIへのポストリクエストの返されたJSON結果に基づいてテーブルを生成するこのd3スクリプトを持っています。 APIには、このPOSTリクエストを実行すると、これは渡された入力パラメータ動作するように期待されている方法ですd3投稿要求にリクエスト本文を正しく渡す方法はありますか?

d3.request("https://erudite-master-api-awsmaui.lab.expts.net/erudite/search") 
.header("Content-Type", "application/json") 
.post("intent=data-quality", function (error,data){ 

         function tabulate(data, columns) { 
          var table = d3.select('#response').append('table') 
          var thead = table.append('thead') 
          var tbody = table.append('tbody'); 

          // append the header row 
          thead.append('tr') 
           .selectAll('th') 
           .data(columns).enter() 
           .append('th') 
           .text(function (column) { return column; }); 

          // create a row for each object in the data 
          var rows = tbody.selectAll('tr') 
           .data(data) 
           .enter() 
           .append('tr'); 

        console.log(data) 
         // create a cell in each row for each column 
         var cells = rows.selectAll('td') 
           .data(function (row) { 
           return columns.map(function (column) { 
            return {column: column, value: row[column]}; 
           }); 
           }) 
           .enter() 
           .append('td') 
           .text(function (d) { return d.value; }); 
         return table; 
        } 
         // render the table 
         tabulate(data, d3.keys(data[0])); 

        }); 

example request body example request/response

を、私はこのスクリプトを実行しているときしかし、私は400エラーコードを取得戻ってきた。リクエストボディを通過している可能性があることを私が知っていると思いますか?しかし100%確かではありません。どんな助けもありがとうございます。

答えて

1

あなたcurlを見てみると、私の推測では、次のようになります。

var data = { 
    "action": "string", 
    "fields": [ 
    "string" 
    ], 
    "filters": {} 
}; 

d3.request("https://erudite-master-api-awsmaui.lab.expts.net/erudite/search?intent=data-quality") 
    .header("Content-Type", "application/json") 
    .post(JSON.stringify(data), function (error,data) { 

    ... 
+0

はありがとう、 ".post(JSON.stringify(データ)は、" 私は必要なものです。 –

0

d3.request("https://erudite-master-api-awsmaui.lab.expts.net/erudite/search") 
    .header("Content-Type", "application/x-www-form-urlencoded") 
    .mimeType("application/json") 
    .post("intent=data-quality", function (error,data){...}); 

を試してみて、あなたはJSONレスポンスを期待している場合は、あなただけの代わりにd3.json使用することができます。

関連する問題