jQuery 文件上传:清理文件队列

jQuery File Upload: clean file queue

我在我的应用程序中使用 JQuery File Upload,每次我添加和上传文件时,它都会再次上传过去添加的文件。这是我每次需要添加新文件时调用的函数。有没有办法在上传成功后清空文件队列?

$(this).fileupload({
        // This function is called when a file is added to the queue;
        // either via the browse button, or via drag/drop:
        replaceFileInput: false,
        autoUpload: false,
        add: function (e, data) {

            // Automatically upload the file once it is added to the queue
            submitBtn.click(function()
            {
                beforeSubmit(function(token, card_side){ input_token.val(token); input_card_side.val(card_side);});
                var jqXHR = data.submit();              
            });
        },
        done: function(e, data)
        {
            try
            {
                var result = typeof data.result == 'string' ? data.result : data.result[0].body.innerHTML;
                $("#fileInputId").replaceWith($("#fileInputId").val('').clone(true));
                callBack(JSON.parse(result));
            }
            catch( e )
            {
                callBack({"result" : "false", "reason" : "Error: " + data.result});
            }
        },
        fail: function(e, data){
            // Something has gone wrong!
            callBack({"result" : "false", "reason" : "server internal error"});
            data.context.addClass('error');
        }

    });

您可以在 done 方法中使用这一行来清除 file/files:

$("#fileInputId").replaceWith($("#fileInputId").val('').clone(true));