I'm trying to get the progress of an ajax request via 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, the progress event only fires once, right before the load event (that is, in Webkit, it doesn't seem to work under Gecko).
Am I doing something wrong or is it just not supported properly?
Use
xhr.upload.addEventListener('progress', function(event) { ... });
(note the added .upload
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With