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

匆匆过客 提交于 2019-12-05 00:54:45

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

Ok, I have found some interesting leads, although not completely good solution yet.

One obvious thing I tried was to play with encodings. There are 2 obvious things that really should work:

  • Latin-1 (aka ISO-8859-1): it is single-byte encoding, mapping one-to-one with Unicode. So theoretically it should be enough to declare content type of "text/plain; charset=ISO-8859-1" and get character-per-byte. Alas, due to idiotic logics of browsers (and even more idiotic mandate by HTML 5!), there is some transcoding occuring which changes high control character range (codes 128 - 159) in strange ways. Apparently this is due to mandatory assumption that encoding really is Windows-1252 (why? For some silly reasons.. but it is what it is)
  • UCS-2 is a fixed-length 2-byte encoding that predated UTF-17; and simply splits 16-bit character codes into 2 bytes. Alas, browsers do not seem to support it.
  • UTF-16 might work, theoretically, but there is the problem of surrogate pair characters (0xD800 - 0xDFFF) which are reserved. And if byte pairs that encode these characters are included, corruption occurs.

However: it seems to conversion for Latin-1 might be reversible, and if so, I bet I could make use of it after all. All mutations are from 1 byte (0x00 - 0xFF) into larger-than-byte values, and there are no ambiguous mappings at least for Firefox. If this holds true for other browsers, it will be possible to map values back and remove ill effects of automatic transcoding. And that would then work for multiple browsers, including IE (with the caveat of needing something special to deal with null values).

Finally, some useful links for conversions of datatypes are:

You can use the JScript "VBArray" object to get at these bytes in IE (without using VBScript):

var data = new VBArray(xhr.responseBody).toArray();

StaxMan

I guess answer is plain "no", as per this post: how do I access XHR responseBody (for binary data) from Javascript in IE?

(or: "use VBScript to help")

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!