Made CSRF JavaScript example more reusable.
This commit is contained in:
parent
ecf87ad513
commit
691b8dd8ed
|
@ -150,12 +150,13 @@ Finally, you'll need to set the header on your AJAX request. Using the
|
||||||
|
|
||||||
const request = new Request(
|
const request = new Request(
|
||||||
/* URL */,
|
/* URL */,
|
||||||
{headers: {'X-CSRFToken': csrftoken}}
|
{
|
||||||
);
|
|
||||||
fetch(request, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
headers: {'X-CSRFToken': csrftoken},
|
||||||
mode: 'same-origin' // Do not send CSRF token to another domain.
|
mode: 'same-origin' // Do not send CSRF token to another domain.
|
||||||
}).then(function(response) {
|
}
|
||||||
|
);
|
||||||
|
fetch(request).then(function(response) {
|
||||||
// ...
|
// ...
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue