1.0.0 • Published 6 years ago

csrf-xhr v1.0.0

Weekly downloads
329
License
BSD-3-Clause
Repository
github
Last release
6 years ago

csrf-xhr

Automatically add Rails CSRF tokens into XMLHttpRequest headers.

How to Use

Load csrf-xhr.js in a <script> anywhere after the <meta name="csrf-token"> that Rails adds to the page.

From now on, any XMLHttpRequest whose destination URL is your local origin (including both relative URLs as well as URLs which explicitly have the same origin as the current page) will have an "X-CSRF-Token" token set to the contents of the <meta name="csrf-token"> that Rails generates in the page's <head>.

jQuery-ujs does this for you; this does it for you even if you aren't using jQuery.

Motivation

This was created to decouple elm-rails from CSRF token management.

1.0.0

6 years ago

0.0.1

7 years ago