Reputation: 258
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
});
Upvotes: 0
Views: 69
Reputation: 19890
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.
Upvotes: 1