Answer the question
In order to leave comments, you need to log in
How to send binary data to shingle with ajax?
Let's say there is this:
var data = new FormData(this);
data.append('csrfmiddlewaretoken', Cookies.get('csrftoken'));
data.append('author', meta.creator);
data.append('title', meta.bookTitle);
data.append('enctype', 'multipart/form-data');
$.ajax({
url: 'ajax/add/',
type: 'POST',
cache: false,
data: data,
processData: false,
contentType: false,
success: function (data) {
console.log('success')
},
error: function (data) {
console.log('error at books/ajax/add')
}
})
def add_book(request):
if request.method == 'POST':
print(request.FILES.get('epub'))
print(request.POST.get('title'))
print(request.POST.get('author'))
else:
return HttpResponseBadRequest()
None
War and Peace
Lev Nikolayevich Tolstoy
<form method="POST" enctype="multipart/form-data" action="{% url 'books:add' %}">
<input type="file" accept="application/epub+zip" id="bookChooser" name="epub">
<button class="btn btn-primary">Submit</button>
</form>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question