27
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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));
27
20
0

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
27
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?