我在我的应用中使用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');
}
});
答案 0 :(得分:2)
您可以在done
方法中使用此一个班轮来清除file/files
:
$("#fileInputId").replaceWith($("#fileInputId").val('').clone(true));