【发布时间】: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