jQuery 文件上传:是否可以使用提交按钮触发上传? [英] jQuery file upload: Is it possible to trigger upload with a submit button?

查看:11
本文介绍了jQuery 文件上传:是否可以使用提交按钮触发上传?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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,我不检查是否是 bindunbind 但 jquery 团队推荐 onoff link 自 1.7 起)

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆