エントリーの編集

エントリーの編集は全ユーザーに共通の機能です。
必ずガイドラインを一読の上ご利用ください。
Fetch APIを使ってRailsのAPIを叩く - The Pragmatic Ball boy
記事へのコメント0件
- 注目コメント
- 新着コメント
このエントリーにコメントしてみましょう。
注目コメント算出アルゴリズムの一部にLINEヤフー株式会社の「建設的コメント順位付けモデルAPI」を使用しています

- バナー広告なし
- ミュート機能あり
- ダークモード搭載
関連記事
Fetch APIを使ってRailsのAPIを叩く - The Pragmatic Ball boy
JavaScript(es2015)でFetch APIを使ってRailsのAPIを呼ぶときの方法。 ポイントとしては、'credentials:... JavaScript(es2015)でFetch APIを使ってRailsのAPIを呼ぶときの方法。 ポイントとしては、'credentials: same-origin'をつけることと、 CSRFを有効にしている場合はheaderにX-CSRF-Tokenをつける点です。 const getCsrfToken = () => { const metas = document.getElementsByTagName('meta'); for (let meta of metas) { if (meta.getAttribute('name') === 'csrf-token') { console.log(meta.getAttribute('content')); return meta.getAttribute('content'); } } return ''; } const p