I am attempting to use an XmlHTTPRequest object (level 2) downloaded through a "GET" request in order to create a new FileReader object.
My goal is to create the FileReader object within the onload function of the xhr. The file, which is a .gz file, downloads successfully and its contents are returned in the xhr response. However, I am encountering an issue where I cannot create a FileReader object from this response. When I attempt to use methods like
readAsText(response.currentTarget.responseText)
, I do not receive the onloadend
event or any other FileReader events.
What could be causing this problem?
Below is the code snippet for the XHR load event:
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);
}