Accessing binary data from Javascript, Ajax, IE: can responseBody be read from Javascript (not VB)?

StaxMan picture StaxMan · Sep 13, 2010 · Viewed 7.8k times · Source

First of all, I am aware of this question:

and specifically best answer therein, http://emilsblog.lerch.org/2009/07/javascript-hacks-using-xhr-to-load.html.

So accessing binary data from Javascript using Firefox (and later versions of Chrome which actually seem to work too; don't know about Opera). So far so good. But I am still hoping to find a way to access binary data with a modern IE (ideally IE 6, but at least IE 7+), without using VB. It has been mentioned that XHR.messageBody would not work (if it contains zero bytes), but I was wondering if this might have been resolved with newer versions; or if there might be alternate settings that would allow simple binary data access.

Specific use case for me is that of accessing data returned by a web service that is encoded using a binary data transfer format (including byte combinations that are not legal in UTF-8 encoding).

Answer

Damien picture Damien · Apr 26, 2013

It's possible with IE10, using responseType=arraybuffer or blob. You only had to wait for a few years...

http://msdn.microsoft.com/en-us/library/ie/br212474%28v=vs.94%29.aspx

http://msdn.microsoft.com/en-us/library/ie/hh673569%28v=vs.85%29.aspx