i made a script for drag and drop a file and upload when submit that script works thanks to Ajax, but i want it without using ajax and so without e.preventDefault();
just like a normal post form... how i should edit it?
form.submit(function (e) {
e.preventDefault();
let formData = new FormData(this);
for (let i = 0; i < filesLoader.length; i++) {
formData.append(filesLoader[i][0], filesLoader[i][1])
}
$.ajax({
type: form.attr('method'),
url: form.attr('action'),
data: formData,
enctype: 'multipart/form-data',
cache: false,
contentType: false,
processData: false,
success: function (data) {
console.log("Success")
},
error: function (data) {
console.log("error")
},
});
});
found the solution, on Drop function i change input field too with fileField.prop("files", e.originalEvent.dataTransfer.files);
thanks to this works for both normal submit or by ajax
dndFileArea.on('drop', function (e) {
let file = e.originalEvent.dataTransfer.files;
fileField.prop("files", e.originalEvent.dataTransfer.files);
filesLoader.push([fileField.attr("name"), file[0]]);