Skip to content

Instantly share code, notes, and snippets.

@pwfisher
Created October 23, 2014 22:56
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 pwfisher/53e10c949537416087c3 to your computer and use it in GitHub Desktop.
Save pwfisher/53e10c949537416087c3 to your computer and use it in GitHub Desktop.
Set XSRF token header for POST, PUT and DELETE requests to relative URLs
//
// Set XSRF token header for POST, PUT and DELETE requests to relative URLs
//
$.ajaxSetup({
beforeSend: function (xhr, settings) {
if (/^https?:/.test(settings.url)) return;
if (!/(POST|PUT|DELETE)/.test(settings.type)) return;
xhr.setRequestHeader('X-XSRF-TOKEN', $.cookie('XSRF-TOKEN'));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment