[whatwg] Provide data chunk with the ProgressEvent

Nicolas Froidure froidure_nicolas at yahoo.fr
Wed Nov 21 08:07:07 PST 2012


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.


More information about the whatwg mailing list