1 // modify jquery ajax to add csrtoken when doing "local" requests
2 $('html').ajaxSend(function(event, xhr, settings) {
3 function getCookie(name) {
4 var cookieValue = null;
5 if (document.cookie && document.cookie != '') {
6 var cookies = document.cookie.split(';');
7 for (var i = 0; i < cookies.length; i++) {
8 var cookie = jQuery.trim(cookies[i]);
9 // Does this cookie string begin with the name we want?
10 if (cookie.substring(0, name.length + 1) == (name + '=')) {
11 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
18 if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
19 // Only send the token to relative URLs i.e. locally.
20 xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));