File upload progress bar with jQuery

前端 未结 9 1613
野的像风
野的像风 2020-11-22 08:52

I am trying to implement an AJAX file upload feature in my project. I am using jQuery for this; my code submits the data using AJAX. I also want to implement a file upload p

9条回答
  •  清酒与你
    2020-11-22 09:43

    Note: This question is related to the jQuery form plugin. If you are searching for a pure jQuery solution, start here. There is no overall jQuery solution for all browser. So you have to use a plugin. I am using dropzone.js, which have an easy fallback for older browsers. Which plugin you prefer depends on your needs. There are a lot of good comparing post out there.

    From the examples:

    jQuery:

    $(function() {
    
        var bar = $('.bar');
        var percent = $('.percent');
        var status = $('#status');
    
        $('form').ajaxForm({
            beforeSend: function() {
                status.empty();
                var percentVal = '0%';
                bar.width(percentVal);
                percent.html(percentVal);
            },
            uploadProgress: function(event, position, total, percentComplete) {
                var percentVal = percentComplete + '%';
                bar.width(percentVal);
                percent.html(percentVal);
            },
            complete: function(xhr) {
                status.html(xhr.responseText);
            }
        });
    }); 
    

    html:


    0%

    you have to style the progressbar with css...

提交回复
热议问题