Setting the token on the AJAX request¶
Finally, you’ll need to set the header on your AJAX request. Using the fetch() API:
const request = new Request( /* URL */, {headers: {'X-CSRFToken': csrftoken}} ); fetch(request, { method: 'POST', mode: 'same-origin' // Do not send CSRF token to another domain. }).then(function(response) { // ... });