Created
June 6, 2012 20:11
-
-
Save McKinneyDigital/2884425 to your computer and use it in GitHub Desktop.
When using AJAX calls to rails methods, send CSRF token to validate the request
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
var csrf_token = $('meta[name=csrf-token]').attr('content'); | |
$("body").bind("ajaxSend", function(elm, xhr, s){ | |
if (s.type == "POST") { | |
xhr.setRequestHeader('X-CSRF-Token', csrf_token); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment