ngx-uploader icon indicating copy to clipboard operation
ngx-uploader copied to clipboard

Some browser does not know XMLHttpRequest.Done property

Open vGhost2000 opened this issue 6 years ago • 0 comments

Some browser does not know XMLHttpRequest.Done property. I try debug in gogle chrome, i add this line in code: ngx-uploader.class.ts:

      xhr.onreadystatechange = () => {

        console.log(xhr.readyState, '===', XMLHttpRequest.DONE); // <<<--- THIS LINE

        if (xhr.readyState === XMLHttpRequest.DONE) {
          const speedAverage = Math.round(file.size / (new Date().getTime() - progressStartTime) * 1000);
          file.progress = {
            status: UploadStatus.Done,
            data: {
              percentage: 100,
              speed: speedAverage,
              speedHuman: `${humanizeBytes(speedAverage)}/s`,
              startTime: progressStartTime,
              endTime: new Date().getTime(),
              eta: eta,
              etaHuman: this.secondsToHuman(eta || 0)
            }
          };

          file.responseStatus = xhr.status;

Get result in console:

4 "===" ƒ () {
            var target = this || _global;
            var eventName = arguments[0];
            if (!eventName) {
                var keys = Object.keys(target);
                for (var i = 0; …

it means that 'done' event never fires because it is a procedure. I changed the code as follows, but I'm not sure that this is the best solution. Please fix the problem in the next version.

      xhr.onreadystatechange = () => {
        // ---- done fix:
        let done = parseInt(XMLHttpRequest.DONE.toString(), 10);
        if (isNaN(done)) {
          done = 4;
        }
        // ---------------
        if (xhr.readyState === done) {
          const speedAverage = Math.round(file.size / (new Date().getTime() - progressStartTime) * 1000);
          file.progress = {

vGhost2000 avatar Nov 06 '18 18:11 vGhost2000