Using Ajax
or xmlHttpRequest
I want to download excel file from django backend. Backend creates file in memory and returns it to user.
According to this answer I should use for this xmlHttpRequest, but there is no info how to set csrf middleware token in post request
.
I tried:
To set request.setRequestHeader
like this:
request.setRequestHeader('x-csrf-token, window.CSRF_TOKEN)
- token is missing
and in data:
request.send({'csrfmiddlewaretoken': window.CSRF_TOKEN, 'req': 'ExportAllMessages'});
I can't find any working solution with Ajax.