JQuery.get - Support "binary" type

JQuery.get - Support "binary" type

Hello,

For a WebGL application, I need to be able to parse a binary encoded file. The basic Ajax request response is a Unicode string with data loss (multiple byte combinations can produce the same non-valid unicode character). An option is available to the XMLHttpRequest component to allow this binary transfer. We just need to add this line:

req.overrideMimeType('text/plain; charset=x-user-defined');

You can read more about this technique at the Mozilla Developer Center: https://developer.mozilla.org/En/Using_XMLHttpRequest#Receiving_binary_data

It doesn't work on all browsers and I couldn't find any workaround for unsupported browsers.

  • Chrome 4.0.295.0: Works
  • Firefox 3.5.7: Works
  • Safari 4.0.4: Works
  • Internet Explorer 8: Does not work. Doesn't have the overrideMimeType method.
  • Opera 10.10: Does not work. Have the overrideMimeType method but doesn't take it in account.

That would be very handy to have this support on jQuery instead of having to rewrite our own custom Ajax handler just for one line. I don't know what is your policy about methods that are not supported by some browsers, but this would be a great addition!

If you want to see an application, I've setup a BinaryReader class that allows you to work with binary stream directly in javascript as you would do in C++, .NET or Java: http://blog.vjeux.com/2010/javascript/javascript-binary-reader.html

-- 
Vjeux