Created
February 29, 2012 15:51
-
-
Save jaddison/1941916 to your computer and use it in GitHub Desktop.
django csrf token in jquery
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
$(document).ready(function() { | |
// Disable caching of AJAX responses | |
$.ajaxSetup ({cache: false}); | |
$('html').ajaxSend(function(event, xhr, settings) { | |
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) { | |
// Only send the token to relative URLs i.e. locally. | |
xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken')); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment