You need to set the contentType
option to false
to prevent jQuery from attempting to coerce the FormData
object into a URL-encoded string when it constructs the request payload. Also, enctype
is not a valid $.ajax
option, so you should remove that.
Django: Problems uploading files with AJAX
-
05-07-2023 - |
Frage
I have a problem when I try to upload files with Ajax in Django. I'm using FormData on Javascript. But the problem is in the server side. The files arrive to request.POST as dataURL, it should arrive to request.FILES, but it's empty.
This is my code:
var form_data = new FormData(document.getElementById("form-theme-edit")),
url = "/theme/edit/1";
$.ajax({
"url" : url,
"method" : "POST",
"enctype": "multipart/form-data",
"data" : form_data,
"processData" : false
});
Lösung
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow