문제

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
});
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top