Created
October 23, 2014 22:56
-
-
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
This file contains hidden or 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
// | |
// 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