PHP Ajax Upload Progress Bar

后端 未结 6 1273
自闭症患者
自闭症患者 2020-11-30 22:56
6条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 23:44

    XMLHTTPREQUSET2

    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'video.avi', true);
    xhr.responseType = 'blob';
    
    xhr.onload = function(e) {
      if (this.status == 200) {
        var blob = this.response;
    /*
        var img = document.createElement('img');
        img.onload = function(e) {
          window.URL.revokeObjectURL(img.src); // Clean up after yourself.
        };
        img.src = window.URL.createObjectURL(blob);
        document.body.appendChild(img);
        /*...*/
      }
    };
    xhr.addEventListener("progress", updateProgress, false);
    xhr.send();
    
    
    
    function updateProgress (oEvent) {
      if (oEvent.lengthComputable) {
        var percentComplete = oEvent.loaded / oEvent.total;
        console.log(percentComplete)
      } else {
        // Unable to compute progress information since the total size is unknown
      }
    }
    

提交回复
热议问题