I am trying to send file to PHP
via ajax.
The problem is that PHP
starts before file is fully uploaded, so $_FILES
is empty.
var data = new FormData();
data.append('file', $('#file').prop('files')[0]);
e.preventDefault();
$.ajax({
xhr: function () {
var xhr = $.ajaxSettings.xhr();
xhr.upload.onprogress = function (e) {
};
return xhr;
},
url: 'upload.php',
type: 'POST',
data: data,
contentType: false,
cache: false,
processData: false
});
});