Last active
May 12, 2019 00:11
-
-
Save localhostdotdev/3c3f9291c0703c9bf9d436da9679d755 to your computer and use it in GitHub Desktop.
post fetch rails json with csrf token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
post = (url, body) -> | |
token = document.querySelector('meta[name="csrf-token"]').attributes.content.value | |
fetch("#{url}.json", | |
method: "POST" | |
mode: "cors" | |
cache: "no-cache" | |
credentials: "same-origin" | |
headers: | |
"Content-Type": "application/json" | |
"X-CSRF-Token": token | |
redirect: "follow" | |
referrer: "no-referrer" | |
body: body | |
).then (response) -> response.json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment