Skip to content

Instantly share code, notes, and snippets.

@Arwid
Created April 19, 2011 23:39
Show Gist options
  • Save Arwid/929995 to your computer and use it in GitHub Desktop.
Save Arwid/929995 to your computer and use it in GitHub Desktop.
include csrf-token in ajax requests
var csrf_token = $("meta[name='csrf-token']").attr("content");
$("body").bind("ajaxSend", function(elm, xhr, s){
if (s.type == "POST" || s.type == "PUT" || s.type == "DELETE") {
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