Create a new FileReader object from downloaded file with XmlHTTPRequest
I am trying to create a new FileReader object from an XmlHTTPRequest object (level 2) which I've downloaded with "GET".
I am trying to create the FileReader object inside the onload of the xhr. The downloading of the file (a .gz file) goes fine and the contents is getting returned in the xhr response. However, I am unable to create a FileReader object from this. The error I am experiencing that I neither get the onloadend
event nor any event in the FileReader after trying doing a readAsText(response.currentTarget.responseText)
or any of the other methods of reading the contents.
What am I missing?
Code for th XHR load even开发者_JS百科t:
function onLoad(e) {
var reader = new FileReader();
reader.onload = function(evt) {
console.log('a');
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
console.log('s');
}
};
reader.readAsText(e.currentTarget.responseText);
I think that what you're missing is that that's simply not what FileReader objects do. They have nothing whatsoever to do with handling responses to HTTP requests. Instead, they're for reading local (to the client machine) files.
精彩评论