javascript - Progress image upload Ajax jQuery -


i have problem ajax progress bar in firefox (on chrome work fine). if upload photo reaches 100%.

$('.img_upload').on('change', function(e) {   var file_data = $('.img_upload').prop('files')[0];   var form_data = new formdata();   form_data.append('file', file_data);   $.ajax({     url: "/admin/ajax/singleimg.php",     datatype: 'text', // expect php script, if     cache: false,     contenttype: false,     processdata: false,     data: form_data,     type: 'post',     xhr: function() {       var myxhr = $.ajaxsettings.xhr();       if (myxhr.upload) {         $('.img_upload').parent().fadeout();         $('.progress').fadein();         myxhr.upload.addeventlistener('progress', progress, false);       }       return myxhr;     },     processdata: false,     contenttype: false,     success: function(data) {       $('#nameimg').val(data);     }   }); }); 

this function progress in firefox percentage

function progress(e) {   if (e.lengthcomputable) {     var max = e.total;     var current = e.loaded;      var percentage = (current * 100) / max;     console.log(percentage);     percentage = parseint(percentage);     $('.progress').fadein();     $('.sr-only').css('position', 'static').html(percentage + '%');     var width = percentage + '%';     $('.progress-bar').css('width', width);     if (percentage >= 100) {       $('#firststep').fadeout();       $('#secondstep').fadein();     }   } } 


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -