When using Ajax to get binaries from the server side, you need to set the request header with Overridemimttype so that the browser does not modify the read data as follows:
var xhr = new XMLHttpRequest ();
Xhr.onreadystatechange = function () {
if (xhr.readystate=== 4 && xhr.status = = 200) {
var imgdata = Xhr.response;
}
}
Xhr.open ("Get", url,true);
Xhr.overridemimetype ("Text/plain; Charset=x-user-defined ");
Xhr.send (NULL);
Also use Xhr.response to get binary data, not responsetext.
If you need to send binary data via Ajax post, you need to change the high order of the binary data to 0 before sending, usually adding a method to the XMLHttpRequest to implement:
XMLHttpRequest.prototype.sendAsBinary = function (datastr) {
function Bytevalue (x) {
Return x.charcodeat (0) & 0xFF;
}
var ords = Array.prototype.map.call (Datastr, Bytevalue);
var ui8a = new Uint8array (ords);
This.send (Ui8a.buffer);
}
var bindata = binary data;
Xhr.open ("POST", url);
Xhr.sendasbinary (Bindata);