jQuery file upload: Is it possible to trigger upload with a submit button?

前端 未结 8 2303
走了就别回头了
走了就别回头了 2020-12-01 01:40

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

8条回答
  •  無奈伤痛
    2020-12-01 02:01

    Make sure not to stack events by attaching event every time the file is added. That way the form will be submitted multiple times.

    I would do something like this

    $('#fileupload').fileupload({
        dataType: 'json',
        add: function (e, data) {            
            $("#up_btn").off('click').on('click', function () {
                data.submit();
            });
        },
    });
    

    Notice the off() method to remove all previous attached events.

提交回复
热议问题