Skip to content

Instantly share code, notes, and snippets.

@lackneets
Last active January 3, 2018 08:45
Show Gist options
  • Save lackneets/c458e1fe8bd43674320893ff90dd1b9d to your computer and use it in GitHub Desktop.
Save lackneets/c458e1fe8bd43674320893ff90dd1b9d to your computer and use it in GitHub Desktop.
// Add to application.js
$("body").bind("ajaxSend", function(elm, xhr, s){
if (s.type == "POST") {
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
}
});
// OR
$.ajaxSetup({
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment