Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMLHttpRequest: Browser support for sendAsBinary?

Is Firefox the only that supports the sendAsBinary method?

like image 914
Alex Polo Avatar asked Nov 21 '10 02:11

Alex Polo


People also ask

Do all browsers support XMLHttpRequest?

All modern browsers (Chrome, Firefox, Edge (and IE7+), Safari, Opera) have a built-in XMLHttpRequest object.

How do I enable XMLHttpRequest in Chrome?

1. Open Chrome browser 2. Go to chrome://flags/#allow-sync-xhr-in-page-dismissal 3. Change the drop-down selection from “Default” or “Disabled” to “Enabled”.

What can I use instead of XMLHttpRequest?

The Fetch API is a modern alternative to XMLHttpRequest . The generic Headers, Request, and Response interfaces provide consistency while Promises permit easier chaining and async/await without callbacks.

Does Internet Explorer support XMLHttpRequest?

Note: XMLHttpRequest advanced features is Partially Supported on Internet Explorer 11.


2 Answers

At the moment, I believe only FF3+ supports this, though there is a workaround for Chrome.

like image 155
Marko Avatar answered Sep 27 '22 21:09

Marko


The links around http://code.google.com/p/chromium/issues/detail?id=35705 are very confusing, but I do not think there is any workaround on Chrome 8 for POST'ing binary data.

You can convert the data to base64 and upload that, but then the server has to be able to decode it.

Chrome 9 (currently in Dev channel, not even Beta yet) lets you do XmlHttpRequest.send(blob) where the blob's bytes are sent as-is (not converted to utf-8), so the non-standard XmlHttpRequest.sendAsBinary() is not necessary for binary file uploads.

You must create this blob from the "binary" string that is in evt.target.result after a successful FileReader.readAsBinaryString(). That requires using ArrayBuffer and Uint8Array, which are not available in Chrome 8.

like image 45
jamshid Avatar answered Sep 27 '22 19:09

jamshid