我在听xhr.onprogress

request.onprogress = function(e){
    return conf.progress ? conf.progress(e) : null;
};
conf.progress在哪里
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在控制台中产生类似于2.789069431137492e-11的错误值,这就是console.log(e)打印的内容
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

为什么e.totalSize: 18446744073709552000如此之大,甚至在文档完全加载后e.loaded: 4982035也是如此,所以totalSize在完成后应等于loaded

最佳答案

实际上,如果您使用的是基于WebKit的浏览器,则很可能是WebKit错误,其中在不检查是否为负数的情况下强制转换了-1的长度:https://bugs.webkit.org/show_bug.cgi?id=36156

09-25 16:56