Ajax upload picture acquisition progress

use ajax to upload pictures, how to get the real upload progress.

Jan.13,2022

    $.ajax({
        url:'url',
        data:formData,
        type: 'POST',
        cache: false,
        contentType: false,
        processData: false,
        success:function(data){
            
        },
        xhr:function(){ //
            var myXhr = $.ajaxSettings.xhr(); 
               if(myXhr.upload){ // check if upload property exists 
                   myXhr.upload.addEventListener('progress',function(e){ 
                       var loaded = e.loaded;//
                    var tot = e.total;//
                    var per = Math.floor(100*loaded/tot);  //
                    console.log(per)
                }, false); 
            }  
              return myXhr;  
          }
    })
Menu