1

I use the ajaxuploader.js to upload pictures.

i use the following piece of code to get the progress of the ajax request:

 jQuery(function($) {
    $.ajaxUploadSettings.name = 'uploads[]';
    $('#pic-upload-area').ajaxUploadPrompt({
        type: 'POST',
        url: "myUrl",
        beforeSend: function() {
           // do sth
        },
        error: function(data) {
           // do sth
        },
        success: function(data) {
            // do sth
        },
        xhrFields: {
            onprogress: function(progress) {
                var percentage = Math.floor((progress.total / progress.totalSize) * 100);
                console.log('progress', percentage);
                if (percentage === 100) {
                    console.log('DONE!');
                }
            }
        },
    });
});

Seems to work, at the ende it logs "process 100" and "DONE!".

But whats with the percentages between 0 and 100? Seems the eventlistener doesnt work properly and fires evry x ms and gets me the current percentage of the upload.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Maybe your upload is short enough that it finishes before there are any percentages to display. – Barmar Aug 16 '14 at 14:40
  • 1
    I had this exact problem and found my answer here [Can onprogress functionality be added to jQuery.ajax() by using xhrFields?][1] [1]: http://stackoverflow.com/questions/15668339/can-onprogress-functionality-be-added-to-jquery-ajax-by-using-xhrfields – Nima Hashemi Nov 27 '14 at 15:08
  • I have the same trouble. Finally I figured out the reason is I'm using the local server, so it uploads file too fast to fire more than one `onprogress` event. – D Nguyen Jun 16 '16 at 08:25

0 Answers0