admin管理员组文章数量:1293159
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?
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?
Share Improve this question asked Nov 7, 2011 at 16:50 DADUDADU 7,0868 gold badges44 silver badges64 bronze badges 9- Are you testing in localhost? – zatatatata Commented Nov 7, 2011 at 17:02
- Yes but the remote host gives the same result. – DADU Commented Nov 7, 2011 at 17:13
- 2 Maybe this does help: stackoverflow./questions/76976/… – Fabian Commented Nov 7, 2011 at 17:18
- @Fabian The answer, stackoverflow./questions/76976/… relies on PHP's readfile. I can't use that because I expect to receive an HTML image element as responseText instead of raw image data. – DADU Commented Nov 7, 2011 at 18:22
- Just make sure your webserver is configured to send the content-length header. – Gerben Commented Nov 7, 2011 at 18:38
1 Answer
Reset to default 11Use
xhr.upload.addEventListener('progress', function(event) { ... });
(note the added .upload
)
本文标签: javascriptXMLHttpRequest 2 download progress event only firing onceStack Overflow
版权声明:本文标题:javascript - XMLHttpRequest 2 download progress event only firing once - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741567807a2385827.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论