2015-06-30 125 views
1

我遇到了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!'); 
        } 
       } 
      }) 
    } 

回答

2

我現在已經設法解決了這個問題。我剛剛添加了一個解除綁定('點擊')的功能,添加了點擊事件,如下所示:

$('#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(); 
         } 
        }) 
       },