Reputation: 1
I tried to upload files with Ajax. But POST request is empty.
var fd = new FormData();
fd.append('file', files[0].name);
alert(files[0].name);
$("#form_upload").submit();
$.ajax({
method: "POST",
url: "/dropupload/",
contentType: false,
processData: false,
data: fd,
success: function(data) {
waitforprocess();
},
complete: function(data){
alert(formdata.size)
},
error: function(){
allert("error")
}
});
in views POST is emty
def post(request):
q = request.POST.get("file")
q = None
Why POST is empty?
Upvotes: 0
Views: 1092
Reputation: 59
Try the following:
var fd = new FormData($("#form")[0]);
Also, make sure, your form declaration is correct:
<form id="form" enctype="multipart/form-data">
<input type="file" name="file" />
</form>
Upvotes: 0
Reputation: 2048
Try serializing the form data instead of creating a new FormData object. Like:
var $form = $("#form_upload").find('form');
var fd = $form.serialize();
// ...
Upvotes: 1