XmlHtt prequest onprogress区间 [英] XmlHttpRequest onprogress interval

查看:271
本文介绍了XmlHtt prequest onprogress区间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用XmlHtt prequests将图像上传到服务器,我想向用户展示这些上传的进度。

I'm using XmlHttpRequests to upload images to a server and I'd like to show the user the progress of these uploads.

不幸的是打到我onprogress事件处理程序之间的间隔过大。通常onprogress被称为只有一次或两次为500K的形象。

Unfortunately the interval between calls to my onprogress-event handler is too large. Usually onprogress is called only once or twice for a 500k image.

下面是我的code:

/* This function is not called often enough */
function progress(e){
    console.log('Uploading: ' + Math.round((e.loaded / e.total) * 100) + ' %');
}

var xhr = new XMLHttpRequest();
xhr.upload.addEventListener('progress', progress, false);
xhr.send(data);

可这种行为被改变,或者这是很难codeD某处在浏览器中执行?

Can this behaviour be changed or is this hardcoded somewhere in the browser implementation?

推荐答案

在W3阐述在他们的 XMLHtt prequest 2级文件。显然,不同的一致性程度不同的浏览器是可以预期的。

The W3 sets forth the following guidelines in their XMLHttpRequest Level 2 document. Obviously varying levels of conformance across browsers are to be expected.

上传:

而请求实体正文正在上传,并上传完成标志是假的,排队一个任务触发一个名为约每50ms或每一个字节XMLHtt prequestUpload对象进度传输进度事件,取其是最常见的。 - W3 XMLHtt prequest 2级(加粗为重点)

While the request entity body is being uploaded and the upload complete flag is false, queue a task to fire a progress event named progress at the XMLHttpRequestUpload object about every 50ms or for every byte transmitted, whichever is least frequent. - W3 XMLHttpRequest Level 2 (Bolded for emphasis)

下载:

当有人说取得进展的通知,而下载的进展,排队任务解雇约每隔50ms或收到的每个字节,取其最频繁 progress事件命名的进步。 - W3 XMLHtt prequest 2级(加粗为重点)

When it is said to make progress notifications, while the download is progressing, queue a task to fire a progress event named progress about every 50ms or for every byte received, whichever is least frequent. - W3 XMLHttpRequest Level 2 (Bolded for emphasis)

我不知道一个API来定义这个功能。

I am not aware of an api to customize this functionality.

这篇关于XmlHtt prequest onprogress区间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆