Reputation: 12904
I am listening on xhr.onprogress
request.onprogress = function(e){
return conf.progress ? conf.progress(e) : null;
};
where conf.progress
is
function(e){
var position = e.position || e.loaded;
var total = e.totalSize || e.total;
var percent = ((e.loaded/e.total)*100)+"";
console.log(percent);
console.log(position, total);
console.log(e);
}
percent
yields wrong value in console like 2.789069431137492e-11
and this is what console.log(e)
prints
XMLHttpRequestProgressEvent
bubbles: false
cancelBubble: false
cancelable: true
clipboardData: undefined
currentTarget: undefined
defaultPrevented: false
eventPhase: 2
lengthComputable: false
loaded: 4982035
position: 4982035
returnValue: true
srcElement: undefined
target: undefined
timeStamp: 1323097256269
total: 18446744073709552000
totalSize: 18446744073709552000
type: "progress"
__proto__: XMLHttpRequestProgressEvent
Why the e.totalSize: 18446744073709552000
is so big and even after the document is completely loaded e.loaded: 4982035
as totalSize
should be equal to loaded
when its complete
Upvotes: 3
Views: 5878
Reputation: 15144
That's because totalSize is set to the maximum value of an unsigned 64-bit integer when it is unknown. You gotta rely on lengthComputable
to check whether a content-length
header was returned or not.
Upvotes: 0
Reputation: 172
Actually, if you're on a WebKit-based browser, it could very likely be a WebKit bug where a length of -1 is being casted without checking for a negative: https://bugs.webkit.org/show_bug.cgi?id=36156
Upvotes: 0