jQuery文件上传:是否可以使用“提交"按钮触发上传? [英] jQuery file upload: Is it possible to trigger upload with a submit button?
问题描述
我正在使用jQuery文件上传基于AJAX的上传.选择文件后,它总是开始上载.是否可以使用提交"按钮更改行为?我知道问题#35 ,但是选项beforeSend
似乎被删除.
I'm using jQuery file upload for AJAX-based uploads. It always starts uploading after a file is selected. Is it possible to change the behavior to use the "submit"-button? I am aware of Issue #35, but the Option beforeSend
seems to have been removed.
我正在使用基本插件,而不是完整版本版本.
I am using the Basic Plugin, not the full version.
也许我应该按照那里的建议切换到基于纯XHR的上传: jQuery上载进度和AJAX文件上载.
Maybe I should just switch to plain-XHR-based uploading as suggested there: jQuery Upload Progress and AJAX file upload.
推荐答案
如果有按钮
<button id="up_btn">Upload</button>
您可以尝试
$('#fileupload').fileupload({
dataType: 'json',
add: function (e, data) {
$("#up_btn").off('click').on('click', function () {
data.submit();
});
},
});
根据评论,更好的答案是off
,以避免重复的请求. (也可以使用unbind
,我不检查是否是bind
和unbind
,但是jquery团队推荐on
和off
according to comments a better answer considere off
to avoid duplicated requests. (also work unbind
, I do not check if is bind
and unbind
but jquery team recommend on
and off
link since 1.7)
这篇关于jQuery文件上传:是否可以使用“提交"按钮触发上传?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!