I use an Ajax request for uploading an image on my server, I use these codes, it works, but it only returns 100% to me, and not any other percentages. What should I do?
$('#uploadImgForm').change(function(e){
var th = $(this);
$.ajax({
url: "post/imageInsert.php",
type: "POST",
data: new FormData(this),
dataType: 'json',
contentType: false,
cache: false,
processData:false,
beforeSend: function(){
$("#imgBack").html('uploading').show();
},
xhr: function()
{
var xhr = new window.XMLHttpRequest();
//Upload progress
xhr.upload.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = Math.floor(evt.loaded / evt.total) * 100 + '%';
$('#progress').css({width : percentComplete});
}
}, false);
return xhr;
},
success: function(data){
if(!data['error']) $("#imgBack").html($('<img>').attr('src',data['success']));
else $("#imgBack").html(data['error']);
},
error: function(){
$("#imgBack").html('Error').hide();
}
});
});