LoginSignup
20

More than 5 years have passed since last update.

axiosでPOSTでRequestしているつもりがOPTIONSで送信している

Last updated at Posted at 2018-09-10

問題

axios.post('/api/fuga', {
        'hoge': hoge
      })
      .then(response => console.log(response))
      .catch(err => console.log(err));

あれ。。。これであってるはずなのに MethodがOPTIONSになってる。。

DevTools_-_localhost_8080_.png

解決

https://github.com/axios/axios#using-applicationx-www-form-urlencoded-format
これ使えば解決しました。

const params = new URLSearchParams();
      params.append('hoge', hoge);
      axios.post('/api/fuga', params)
        .then(response => console.log(response))
        .catch(err => console.log(err));

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20