Answer the question
In order to leave comments, you need to log in
What to do with CSRF token missing or incorrect?
I want to send recorded audio file to View using AJAX. Writes a message:
Forbidden (CSRF token missing or incorrect.)
console.log("Остановка записи")
rec.stop()
gumStream.getAudioTracks()[0].stop();
$('#btnToStopRecord').attr('id', 'btnToRecord');
$("#toMessage").prop('disabled', false).attr('placeholder', "Введите сообщение...")
rec.exportWAV(function (blob) {
let data = new FormData()
data.append('csrfmiddlewaretoken', '{{ csrf_token }}')
data.append('audio', blob)
console.log(data)
$.ajax({
type: "POST",
url: '{% url 'sendtext' %}',
contentType: false,
cache: false,
processData: false,
data: {
'audioFile': data,
'csrfmiddlewaretoken': '{{ csrf_token }}',
},
})
Answer the question
In order to leave comments, you need to log in
You need to get a csrf token from the backend, and then send it back to the backend from the client along with a request.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question