OwenMoriarty
asked on
Binary response from webservice, convert to text?
I have access to a webservice that returns binary data. I have set up an ajax request that returns text like the following,
(q/¿M¿ ¿¿¿&PB¿¿¿¿p/¿MA¿¿&PB¿¿¿¿¿=¿MH¿¿&PB¿¿¿ ¿¿K¿M2¿¿¿PB¿¿¿¿p/¿M J¿¿¿PB¿¿¿¿¿=¿MG¿¿¿PB¿¿¿¿¿K¿M B¿SYQB¿I¿¿p/¿M T¿
How do I use this data? Is the browser already interpreting it? I can request the data as json but their is so much of it that the request takes >60seconds so we are trying to transfer the data in binary and interpret it on the client. This transfer is an order of magnitude faster.
(q/¿M¿ ¿¿¿&PB¿¿¿¿p/¿MA¿¿&PB¿¿¿¿¿=¿MH¿¿&PB¿¿¿
How do I use this data? Is the browser already interpreting it? I can request the data as json but their is so much of it that the request takes >60seconds so we are trying to transfer the data in binary and interpret it on the client. This transfer is an order of magnitude faster.
function loadXMLDoc(){
var url = "http://10.10.10.10/pa/pa/pd";
var params = "times=1303916400%2C0%2C0&timerange=0..2&areas=53%2C-8%2C52%2C-8%2C54%2C-8&ndp=1%2C2%2C6%2C7%2C14%2C17%2C18%2C19&server=10.50.50.10&command=grid&obs=";
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
02
xhr.open("GET", "binary_file", false);
03
xhr.send(null);
04
05
buffer = xhr.mozResponseArrayBuffer
06
if (buffer) {
07
var byteArray = new Uint8Array(buffer);
08
for (var i=0; i<byteArray.byteLength; i++) {
09
// do something with each byte in the array
10
}
11
}
https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Receiving_binary_data
refer :