XMLHttpRequest: browser support for sendAsBinary?

Is Firefox the only one supporting sendAsBinary?

+5
source share
5 answers

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

+3
source

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

You can convert the data to base64 and load it, but then the server should be able to decode it.

Chrome 9 ( Dev, Beta) XmlHttpRequest.send(blob), BLOB ( utf-8), XmlHttpRequest. sendAsBinary() .

blob "" , evt.target.result FileReader.readAsBinaryString(). ArrayBuffer Uint8Array, Chrome 8.

+2

, , Firefox . W3C, , - .

+1

I had the same error, but I also use Prototype.js. It seems to have a replacement for the map function, and it threw a TypeError for me Object ..file data here.. has no method 'each' , so I used this replacement instead

//fix sendAsBinary for chrome
try {
  if (typeof XMLHttpRequest.prototype.sendAsBinary == 'undefined') {
    XMLHttpRequest.prototype.sendAsBinary = function(text){
      var data = new ArrayBuffer(text.length);
      var ui8a = new Uint8Array(data, 0);
      for (var i = 0; i < text.length; i++) ui8a[i] = (text.charCodeAt(i) & 0xff);
      this.send(ui8a);
    }
  }
} catch (e) {}
+1
source

The workaround for Chrome is explained at the following URL:

http://code.google.com/p/chromium/issues/detail?id=35705

0
source

All Articles