【问题标题】:Confirm before upload button click Blueimp JQuery fileupload上传前确认按钮单击 Blueimp JQuery 文件上传
【发布时间】:2015-09-17 03:14:46
【问题描述】:

我遇到了 Blueimp JQuery AJAX 文件上传插件的问题。 我想要做的是将一个函数绑定到上传按钮,以便在单击上传按钮时显示确认警报。问题是我在 ajax 调用中使用 add: 选项,这会在选择要上传的文件时添加该函数,这会导致确认消息出现 x 次用户选择要上传的文件。有没有办法解决这个问题?

function setUploadBtnForm1(token){
        var regexp = new RegExp("/settings\$", "i");
        var url = window.location.origin + window.location.pathname.replace(regexp, '/ajaxUploadSigFile');
            $('#fileUpload').fileupload({
                formData: {_token: token},
                datatype:'json',
                url:url,
                allowedTypes:'png',
                add:function(e, data){
                            $('#signatureUploadBtn1').click(function(){
                                var response = confirm('This will remove the existing signature are you sure?');
                                if(response == true)
                                {
                                    data.submit();
                                }else{
                                    e.preventDefault();
                                }
                    });
                },
                success: function(data){
                    var query = data;
                    if (query.RESULT == 'PASS')
                    {
                        $('#signatureUploadBtn1').hide();
                        //set src attribute of signature image to filename of uploaded file.
                        $('.sigImage1').attr('src', '../images/signatures/'+query.FILENAME);
                            $('.modalLoadContent').fadeOut('fast');
                            $('.modalFinishContent').show();
                    }else{
                        $('#signatureUploadBtn1').text('Failed!');
                    }
                }
            })
    }

【问题讨论】:

    标签: jquery ajax file upload confirm


    【解决方案1】:

    我现在实际上已经设法解决了这个问题。我刚刚在添加点击事件的函数中添加了一个 unbind('click'),如下所示:

    $('#fileUpload1').fileupload({
                    formData: {_token: token},
                    datatype:'json',
                    url:url,
                    allowedTypes:'png',
                    replaceFileInput:false,
                    autoUpload:false,
                    add:function(e, data){
                        uploadButton.unbind('click');
                        uploadButton.click(function(){
                            var response = confirm('This will remove the existing signature are you sure?');
                            if(response == true)
                            {
                                data.submit();
                            }else{
                                data.abort();
                            }
                        })
                    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-14
      • 2013-04-29
      相关资源
      最近更新 更多