Hi guys, how to create a upload preloader using app.request to upload an image. I don’t want to use jQuery, but the XHR callback is not present on app.request. Any idea?
My code in jQuery that is working:
var fd = new FormData();
fd.append('id', id);
fd.append('image', $('#img-upload-'+position).prop('files')[0]);
fd.append('position', position);
$.ajax({
url: "my-upload-script.php",
type: "POST",
data: fd,
timeout: 30000,
cache: false,
contentType: false,
processData: false,
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
percentComplete = parseInt(percentComplete * 100);
$('.preloader-'+position+' div').animate({ height: percentComplete + '%' }, { duration: 1000 });
if(evt.loaded == evt.total){
$(".preloader-"+position).fadeOut('fast', function(){ $(this).remove(); });
blockEl("block", ".img-"+position, "0px", "Adjusting");
}
}
}, !1);
return xhr
},
success: function(data, status, xhr) {
var result = $.parseJSON(data);
var status = result.status;
}
}).fail(function (jqXHR, textStatus, errorThrown) {
show_errors_ajax(jqXHR.status);
});