1

I want to download a zip file from a url as binary array using XMLHttpRequest.responseBody and then save it as a file. How can I do that?

I am using IE 8 and have reached till receving the xmlhttprequest.responsebody and convert it to text format.

how do I access XHR responseBody (for binary data) from Javascript in IE?

but what then? how do I save these array of bytes as file?

I am quite new to javascript and php.

function httpPost1(theUrl,param)
{

  var xmlHttp = null;

  xmlHttp = new XMLHttpRequest();

  xmlHttp.open( "POST", theUrl+"?"+param, true);
  xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Accept-Charset", "x-user-defined");

  xmlHttp.onreadystatechange =function(){

        if(xmlHttp.readyState==4)
     {   
           if(xmlHttp.status==200)
        {           
           // convert to string format from resonse
           var fileContents = convertResponseBodyToText(xmlHttp.responseBody);
           var bresults =[];  // convert to sring response to array of integers
           for (var i=0; i<fileContents.length; i++)
             {
           bresults[i] =fileContents.charCodeAt(i) & 0xff
             }

             // how will i save the array as file?
         }

          }
        }
    xmlHttp.send();
}

As I am using with older versions of IE8, use of FileAPI, FileReader, FileWriter nothing worked.

Any help will be appreciated.

Community
  • 1
  • 1
  • Why not simply let the user download the file? – Bergi Apr 04 '14 at 12:01
  • well, the scenario is quite different here.The downloading URL is of a local system in the client LAN. So once I have recieved the binary data using xhr, I want to save it at the server system(using jscript) or directly upload the binary data to PHP script which might be able to save it as file. – user3490933 Apr 04 '14 at 12:14

0 Answers0