- From: Nicolas Froidure <froidure_nicolas@yahoo.fr>
- Date: Wed, 21 Nov 2012 17:07:07 +0100
- To: whatwg@lists.whatwg.org
I'm currently working on a way to update UI before the all XHR datas to
be loaded (sample
<http://server.elitwork.com/experiments/pagestream/index.html>)
For that need i used the progress listener
<http://dvcs.w3.org/hg/progress/raw-file/tip/Overview.html#progressevent> but
it's particularly unadapted to it's use.
Indeed, the only way to access to the data chunk loaded is to keep a
reference to the previous value of xhr.responseText.
I think it could be more usefull if the progress event was providing a
chunk property containing only the new datas loaded. So we could do that :
var myXhr=new XMLHttpRequest();
var mylist=document.getElementById('mylist');
myXhr.open("GET", "entries.dat", true);
myXhr.onprogress=function(event)
{
var item=document.createElement('li');
item.innerHTML=event.chunk;
myList.appendChild(item);
}
myXhr.send(null);
Instead of :
var myXhr=new XMLHttpRequest();
var mylist=document.getElementById('mylist');
myXhr.open("GET", "entries.dat", true);
var previousContentLength=0;
myXhr.onprogress=function()
{
var item=document.createElement('li');
item.innerHTML=myXhr.responseText.substr(previousContentLength);
previousContentLength=myXhr.responseText.length;
myList.appendChild(item);
}
myXhr.send(null);
Regards, Nicolas Froidure.
Received on Wednesday, 21 November 2012 16:20:55 UTC