We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Binary response from webservice, convert to text?

OwenMoriarty
OwenMoriarty asked
on
Medium Priority
838 Views
Last Modified: 2012-05-11
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/¿M A¿¿&PB¿¿¿¿¿=¿MH¿¿&PB¿¿¿¿¿K¿M 2¿¿¿PB¿¿¿¿p/¿M J¿¿¿PB¿¿¿¿¿=¿M G¿¿¿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.
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);

}

Open in new window

Comment
Watch Question

Gk

Commented:
var xhr = new XMLHttpRequest();
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 :
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.