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.