XMLHttpRequest 2 event event loading only once

I am trying to get the ajax request progress through the following code:

var xhr = new XMLHttpRequest(); xhr.addEventListener('progress', function(event) { console.log(event.loaded / event.total); }, false); xhr.addEventListener('load', function() { console.log('load'); }, false); xhr.open('get', 'test.php', true); xhr.send(); 

The problem is that the progress event is fired only once, right before the load event (that is, in Webkit, it seems that it does not work under Gecko).

Am I doing something wrong or just not being supported properly?

+4
source share
1 answer

Use

 xhr.upload.addEventListener('progress', function(event) { ... }); 

(note the added .upload )

+11
source

Source: https://habr.com/ru/post/1380027/


All Articles