We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 8bc3c90 + a0914fc commit 18c5b30Copy full SHA for 18c5b30
jsapp/js/main.es6
@@ -25,10 +25,18 @@ function csrfSafeMethod(method) {
25
// these HTTP methods do not require CSRF protection
26
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
27
}
28
+
29
+let csrfToken = '';
30
+try {
31
+ csrfToken = document.cookie.match(/csrftoken=(\w{64})/)[1];
32
+} catch (err) {
33
+ console.error('Cookie not matched');
34
+}
35
36
$.ajaxSetup({
37
beforeSend: function(xhr, settings) {
38
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
- xhr.setRequestHeader('X-CSRFToken', cookies.get('csrftoken'));
39
+ xhr.setRequestHeader('X-CSRFToken', csrfToken || cookies.get('csrftoken'));
40
41
42
});
0 commit comments