function fetchJSONData(url, callback){
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.onprogress = function(event){
console.log(event.loaded, event.total);
};
request.addEventListener('load', function(){
if(request.status < 400){
callback(request);
}
});
request.send(null);
}
fetchJSONData('http://api.open-notify.org/astros.json', function(data){
console.log(data.responseText);
});
I have a few queries:
1. What kind of event is passed to the function request.onprogress()
?
2. Why am I unable to see request.onprogress()
being called? Instead, there is a property with a value of null
before it was initialized:
Check screenshot in console
3. Is this event propagated to the function every time or only on event trigger? If it's upon event trigger, why can't I find
request.addEventListener('event', request.onprogress())
anywhere?