Abort a multiple file upload AJAX request

前端 未结 1 792
我在风中等你
我在风中等你 2021-02-06 13:24

I am trying to abort a multiple file upload with a progress bar, showing the state of the process.

What I want to achieve is to completely abort the multiple file upload

相关标签:
1条回答
  • 2021-02-06 14:05

    Try this:

    var XHR = new window.XMLHttpRequest();
    var AJAX = $.ajax({ 
        xhr: function() {
            XHR.upload.addEventListener('progress', function(e) {
              if (e.lengthComputable) {
    
                var PROGRESS = Math.round((e.loaded/e.total)*100);
                $('#PROGRESS_BAR').text(PROGRESS);
    
            } }, false); return XHR; },
        url        : '/php.php',
        type       : 'POST',
        data       : DATA,
        cache      : false,
        processData: false,
        contentType: false,
        beforeSend : function() { }, 
        success    : function() { } 
    });
    
    $(document).on('click', '.ABORT', function(e){      
        XHR.abort();
    });
    
    0 讨论(0)
提交回复
热议问题