Why don't jQuery File Upload plugin's process events trigger?

时光怂恿深爱的人放手 提交于 2019-12-06 04:10:01

First syntax

If you want to start the process you have to call data.submit(); into the add fnction.

Then you can't call a processalways callback, according to the documentation it's always which should be used :

$('input').fileupload({
    url: "/echo/json",
    add: function (e, data) {
        console.log("Add callback");
        $('#start_upload').click(function(){
            data.submit();
        });
    },
    always: function (e, data) {
        console.log("Always callback");
    }
});

Second syntax

I've never use it, but if it works it's because fileuploadd doesn't exist. And so it's the default fileuploadadd which is used, and it may call data.submit().

I had read a bit code in jquery.fileupload-ui.js

Maybe this is what you want?

// The add callback is invoked as soon as files are added to the fileupload
// widget (via file input selection, drag & drop or add API call).
// See the basic file upload widget for more information:
add: function (e, data) {
    if (e.isDefaultPrevented()) {
        return false;
    }
    var $this = $(this),
        that = $this.data('blueimp-fileupload') ||
            $this.data('fileupload'),
        options = that.options;
    data.context = that._renderUpload(data.files)
        .data('data', data)
        .addClass('processing');
    options.filesContainer[
        options.prependFiles ? 'prepend' : 'append'
        ](data.context);
    that._forceReflow(data.context);
    that._transition(data.context);
    data.process(function () {
        return $this.fileupload('process', data);
    }).always(function () {
        data.context.each(function (index) {
            $(this).find('.size').text(
                that._formatFileSize(data.files[index].size)
            );
        }).removeClass('processing');
        that._renderPreviews(data);
    }).done(function () {
        data.context.find('.start').prop('disabled', false);
        if ((that._trigger('added', e, data) !== false) &&
            (options.autoUpload || data.autoUpload) &&
            data.autoUpload !== false) {
            data.submit();
        }
    }).fail(function () {
        if (data.files.error) {
            data.context.each(function (index) {
                var error = data.files[index].error;
                if (error) {
                    $(this).find('.error').text(error);
                }
            });
        }
    });
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!