Skip to content

Instantly share code, notes, and snippets.

@s-aska
Created June 15, 2011 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-aska/1026632 to your computer and use it in GitHub Desktop.
Save s-aska/1026632 to your computer and use it in GitHub Desktop.
ajax with csrf_token
// https://github.com/tokuhirom/Amon/blob/master/lib/Amon2/Plugin/Web/CSRFDefender.pm
function ajax(option) {
this.token_name = 'csrf_token'; // 実際は別のところでsetupしておく
if ("data" in option && "type" in option && option.type.toLowerCase() == 'post') {
if (!this.token) {
this.token = $('input[name=' + this.token_name + ']:first').val();
}
option.data[this.token_name] = this.token;
}
return $.ajax(option);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment