我正在使用XmlHttpRequests將圖像上傳到服務器,我想向用戶顯示這些上傳的進度。XmlHttpRequest onprogress間隔
不幸的是,調用我的onprogress-event處理程序之間的間隔太大。對於500k圖像,通常只對一次或兩次調用進行中。
這裏是我的代碼:
/* 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);
可這種行爲被改變或在某個地方硬編碼在瀏覽器中實現?
這個怎麼樣? [如何從XMLHttpRequest取得進展](http://stackoverflow.com/questions/76976/how-to-get-progress-from-xmlhttprequest) – mplungjan 2011-03-31 06:07:20
@mplungjan我的問題是沒有取得進展。我的問題是我的事件處理程序被調用的頻率。我已更新我的問題以澄清。 – Oscar 2011-03-31 07:50:12
@Oscar - 我意識到,但是我發佈的線程有很多各種方式的示例 – mplungjan 2011-03-31 08:17:42