4

私は驚くほど強力なD3(データの視覚化に完全に推奨できます)を使用してPOSTリクエストを作成する方法を調査していて、 D3の作成者が現在xhr POSTリクエスト(およびその他のリクエストタイプ)に取り組んでいるxhr2ブランチを見つけましたサポート。

マージリクエストは昨日(2012年9月18日)からのものであるため、これはまったく新しい機能のようです:)そして、好奇心旺盛な私は、次のコードシーケンス(この場所から持っています)を使用して、すでに試してみたいと思っています。

 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");

残念ながら、次のエラーメッセージが表示されます。

TypeError:'undefined'は関数ではありません('d3.text( "localhost / test"、function(d){console.log(d)}).method( "POST")'を評価しています)

xhr2ブランチの縮小されたD3バージョンを使用しています。誰かが何を変えるべきか考えていますか?

4

1 に答える 1

11

The API is still under development. If you want to try it out, the current API is like so:

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 rather than d3.text directly if you want the full request object rather than just the responseText.

Edit: Updated to latest API.

于 2012-09-19T16:25:18.700 に答える