开发者

Create a new FileReader object from downloaded file with XmlHTTPRequest

开发者 https://www.devze.com 2023-03-19 23:13 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消