上传前确认按钮点击Blueimp JQuery文件上传
问题描述:
我遇到了Blueimp JQuery AJAX文件上传插件的问题。 我想要做的就是绑定一个函数到上传按钮来显示确认提醒,当点击上传按钮时。问题是我正在使用ajax调用中的add:选项,并且这会在选择要上载的文件时添加函数,这会导致确认消息显示x次,用户选择要上载的文件。有没有办法解决这个问题?上传前确认按钮点击Blueimp JQuery文件上传
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!');
}
}
})
}
答
我现在已经设法解决了这个问题。我刚刚添加了一个解除绑定('点击')的功能,添加了点击事件,如下所示:
$('#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();
}
})
},