Is the data:..
line below correct? I want to post the form data AND csrf token to a Django view function.
$('#file-upload').on('change', function () {
var currentpath = window.location.pathname;
var formData = new FormData($('form')[0]);
$.ajax({
url: currentpath, //server script to process data
type: 'POST',
data: {formData, 'csrfmiddlewaretoken': '{{ csrf_token }}'},
cache: false,
contentType: false,
processData: false
});
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…