update progress bar using ajax request seconds

后端 未结 2 2081
逝去的感伤
逝去的感伤 2020-12-01 05:30

Basicaly, I\'m performing an AJAX request for an external login system, how can I update the progress bar based on the length of the request?

For example, the reques

2条回答
  •  情话喂你
    2020-12-01 06:13

    I think this post is quite clear http://www.dave-bond.com/blog/2010/01/JQuery-ajax-progress-HMTL5/

    Posting this for future reference (should the blog be removed):

    $.ajax({
         xhr: function(){
           var xhr = new window.XMLHttpRequest();
           //Upload progress
           xhr.upload.addEventListener("progress", function(evt){
           if (evt.lengthComputable) {
             var percentComplete = evt.loaded / evt.total;
             //Do something with upload progress
             console.log(percentComplete);
             }
           }, false);
         //Download progress
           xhr.addEventListener("progress", function(evt){
             if (evt.lengthComputable) {
               var percentComplete = evt.loaded / evt.total;
             //Do something with download progress
               console.log(percentComplete);
             }
           }, false);
           return xhr;
         },
         type: 'POST',
         url: "/",
         data: {},
         success: function(data){
        //Do something success-ish
        }
     });
    

提交回复
热议问题