简体   繁体   English

在上传过程中取消异步jquery文件上传

[英]Cancel an asynchronous jquery file upload during the upload

I need to be able to cancel an upload while it is uploading. 我需要能够在上传时取消上传。 I have found https://github.com/blueimp/jQuery-File-Upload/wiki/API#how-to-cancel-an-upload however that depends on you not using the options object. 我已经找到https://github.com/blueimp/jQuery-File-Upload/wiki/API#how-to-cancel-an-upload,但这取决于您是否不使用options对象。 I am using the options object. 我正在使用options对象。

When you do 当你做

var jqXHR = $('#fileupload').fileupload('send', {files: filesList})

it returns an object you can call .abort() on. 它返回一个可以调用.abort()的对象。

However, when you just use the options object 但是,当您仅使用options对象时

$('#fileupload').fileupload({url:'...',add: function(e, data){data.submit();}});

then it returns the jquery selector for '#fileupload' 然后返回'#fileupload'的jquery选择器

I'm lost as to how to trigger a cancel upload after you do data.submit() 我不知道如何在执行data.submit()之后触发取消上传

To do this, the object is returned on the data.submit(); 为此,将对象返回到data.submit();上。

$('#fileupload').fileupload({
  url:'...',
  add: function(e, data){
    var jqXHR = data.submit();

    // Setup event handler
    form.find('.cancel_upload').on('click', function(){
      jqXHR.abort();
    });
  }
});

And that is how you can get to the abort method. 这就是您进入中止方法的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM