$('html').ajaxSend(function(event,xhr,settings){functiongetCookie(name){varcookieValue=null;if(document.cookie&&document.cookie!=''){varcookies=document.cookie.split(';');for(vari=0;i<cookies.length;i++){varcookie=jQuery.trim(cookies[i]);// Does this cookie string begin with the name we want?if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}returncookieValue;}if(!(/^http:.*/.test(settings.url)||/^https:.*/.test(settings.url))){// Only send the token to relative URLs i.e. locally.xhr.setRequestHeader("X-CSRFToken",getCookie('csrftoken'));}});