Ugent !!!在Blueimp jquery文件上传

时间:2015-08-20 09:24:28

标签: javascript jquery html file-upload blueimp

我正在尝试使用BLueimp文件上传Jquery上传表单,但我无法中止所有文件上传。我的移民是:

url: form.attr('action'),
                type: 'POST',
                datatype: 'json',
                        dropZone: $(document),
                        pasteZone: $(document),
                        singleFileUploads: true,
                        limitConcurrentUploads: 1,

我不能改变任何移民。我的意思是singleFileUploads:true是必须的。 我也试过

xqXHr = data.submit();

但是中止它只会中止1个文件而不是全部。我一直在寻找5个小时,但找不到答案:(。

完整的js代码

    $(document).on('click','.redbut',function(){
      jqXHR.abort();
        jqXHR = null;
        });
        $(document).bind('drop dragover', function (e) {
      e.preventDefault();
     });
        setInterval(function(){
          q=0;
      $('.upf_percent').each( function(index){
          q=71*index;
          $(this).css('top', q + "px");
      })  ;   
         }, 100);
                             $(document).ready( function() {     
                      check_nf();
              $('.direct-upload').each( function(n) {
            var form = $(this);
                  'use strict';
            form.fileupload({
                url: form.attr('action'),
                type: 'POST',
                datatype: 'json',
                        dropZone: $(document),
                        pasteZone: $(document),
                        singleFileUploads: true,
                        limitConcurrentUploads: 1,
                add: function (event, data) {
                            window.onbeforeunload = function() {
                return 'Are you sure you want to cancel file uploads.';
            };
                     show_ub();
          $.each(data.files, function (index, file) {
         var size = formatFileSize(file.size);
                var filename = file.name;
                var r_s = makeid(5);
                file.uploadID = r_s;
                $('.direct-upload').append('<div class="u_daba '+r_s+'"><div                                     class="file_data"></div><div class="upf_percent"><div class="arrowdown">0%</div>         </div><div class="progress"><div class="bar"></div></div></div>');
                        check_nf();
                    $('.'+r_s+' .file_data').html(filename+' <span class="marginL15">( '+size+' )</span><span class="floatRight marginR30 blue"><i>Pending</i></span>');
                     n++;
           });
                         jqXHR = data.submit();
    },
                progress: function(e, data){
                            $.each(data.files, function (index, file ) {
                    var p = Math.round((data.loaded / data.total) * 100); 
                            var r_s = file.uploadID;
                    $('.'+r_s+' .progress .bar').css('width', p + '%');
                            $('.'+r_s+' .upf_percent').html('<div class="arrowdown"></div>'+p + '%');
                            if(p>0){
                                $('.'+r_s+' .upf_percent').css('display', "block");
                                $('.'+r_s+' .file_data span:nth-of-type(2)').text('Uploading');
                                $('.'+r_s+' .file_data span:nth-of-type(2)').addClass('green');
                                $('.'+r_s+' .file_data span:nth-of-type(2)').removeClass('blue');
                            }
                            t = 0.9537*p + 1.13;
                            $('.'+r_s+' .upf_percent').css('left', t + "%");
                        });
                            },
                fail: function(e, data) {
                    // Remove 'unsaved changes' message.
                    window.onbeforeunload = null;
                            $.each(data.files, function (index, file ) {
                            var r_s = file.uploadID;
                    $('.'+r_s+' .progress .bar').css('width', '100%').addClass('red');
                            $('.'+r_s+' .upf_percent').css('display', "none");
                                $('.'+r_s+' .file_data span:nth-of-type(2)').text('Error: '+data.errorThrown);
                                $('.'+r_s+' .file_data span:nth-of-type(2)').addClass('red');
                                $('.'+r_s+' .file_data span:nth-of-type(2)').removeClass('green');
                        });
                },
                        done: function (event,data){
                            $.each(data.files, function (index, file ) {
                            var r_s = file.uploadID;
                            $('.'+r_s+' .file_data span:nth-of-type(2)').text('Uploaded Successfully !!');
                            $('.'+r_s+' .upf_percent').css('display', "none");
                                });
                        },
                stop: function (event, data) {
                    window.onbeforeunload = null;
                                     hide_ub();
                                 get_fffi();                  
                }
            });
        });
                });
                $(document).on('click','.uploadbut',function(){
                    $('.direct-upload #file').click();
                });

0 个答案:

没有答案