Reputation: 11663
My Ajax code:
var upfile = $("#file-id").val().split(/[\/\\]/).pop();
$.ajax({
type: 'POST',
url: '/upload/',
data:{"upfile":upfile},
success: function(data) {
if (data['success'] === "true") {
}
},
dataType: 'json'
});
return false;
Django code:
In simple form submit action request.FILES.get('upfile')
works. I can read the content of file using read()
But in ajax, it is not working. even request.POST.get('upfile')
gives me the filename string.
How to solve this issue?
Upvotes: 1
Views: 387
Reputation: 630
It's normal, by default a form submitted with Ajax will not upload files. You need o have a look to some file upload jquery plugins (there's a few of them, I can not suggest one as I did not try any of these yet)
Upvotes: 2