現在Reactでアプリケーションを作っています。
これまでjQueryを使っていたので、ajaxにてデータを送っていたのですが、
Reactになったため、Superagentを使っています。
Superagent github.com
これまではjQueryだったのでこのようなコードでajaxをしていましたが、
これをsuperagentに書き換えるやり方がわかりません。
import $ from "jquery"; $.ajax({ url: 'http://localhost:3000/datas', type: 'POST', dataType: 'json', data: { user: { email: "hello@example.com", password: "12345678" } }, success: function(data){ console.log(data); }, error: function(data){ console.log("error"); console.log(data); } });
特にdatatypeの書き方がわかりません。
Request .post("http://localhost:3000/datas") .send({ user: { email: "hello@example.com", password: "12345678" } }) .end(function(error, response){ console.log(error); console.log(response); })
このコードではできませんでした。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。