Start Upload all in jquery file upload blueimp

﹥>﹥吖頭↗ 提交于 2019-11-29 17:39:55

问题


I use jQuery file upload blueimp and have read

$(function () {
    $('#fileupload').fileupload({
        dataType: 'json',
        done: function (e, data) {
            $.each(data.result, function (index, file) {
                $('<p/>').text(file.name).appendTo(document.body);
            });
        },
        add:function (e, data) {
            $("#uploadBtn").off('click').on('click',function () {
                data.submit();
            });
        }
    });
});

but this uploads a single file, I want to upload all files that have been selected.


回答1:


your problem is that you unbind the click event on every file. you should do it on done:

done: function (e, data) {
            $("#uploadBtn").off('click')
            $.each(data.result, function (index, file) {
                $('<p/>').text(file.name).appendTo(document.body);
            });
        },
add: function (e, data) {
            $("#uploadBtn").on('click',function () {
                data.submit();
            });
        }



回答2:


var pendingList: [];

var sendAll: function () {
        pendingList.forEach(function (data) { data.submit(); });
        pendingList = [];
    };

$('#fileupload').fileupload({
    url: 'url_path',
    autoUpload: false,

    add: function (e, data) {
            pendingList.push(data);
        },


});

<button onclick="sendAll()">Start Upload All</button>



回答3:


below code may be useful.

$('#fileupload').fileupload({
    dataType: 'json',
    add: function (e, data) {
        var that = this;
        $.blueimp.fileupload.prototype.options.add.call(that, e, data);
        $("#up_btn").on('click', function () {
            data.submit();
        });
    },
});



回答4:


For upload concurrently all file you have selected, you can add the option autoUpload: true, like this:

$('#fileupload').fileupload({
    url: 'url_path',
    autoUpload: true
})

Reference: https://github.com/blueimp/jQuery-File-Upload/wiki/Options



来源:https://stackoverflow.com/questions/20740426/start-upload-all-in-jquery-file-upload-blueimp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!