Skip to content

rtfeldman/csrf-xhr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Automatically add Rails CSRF tokens into XMLHttpRequest headers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published