XMLHttpRequest 2下载进度事件仅触发一次

DAD*_*ADU 5 javascript ajax html5 xmlhttprequest-level2

我试图通过以下代码获取ajax请求的进度:

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();
Run Code Online (Sandbox Code Playgroud)

问题是,progress事件只在load事件发生之前触发一次(也就是说,在Webkit中,它似乎不能在Gecko下工作).

我做错了什么还是不正确支持?

Her*_* S. 11

使用

xhr.upload.addEventListener('progress', function(event) { ... });
Run Code Online (Sandbox Code Playgroud)

(注意添加.upload)

  • OP在问题中说"下载",你的答案将提供有关上传部分的信息 (4认同)