The HTML5 AJAX 2.0 standard enhances many features of Ajax, including sending Formdata data, uploading data progress bars, and more. In practice, however, Ajax can send binary data in bytes.
Send binary data
var oreq = new XMLHttpRequest ();
Oreq.open ("POST", url, true);
Oreq.onload = function (oevent) {
//uploaded.
};
var blob = new blob ([' abc123 '], {type: ' Text/plain '});
Oreq.send (BLOB);
Or
var myarray = new Arraybuffer (in);
var longint8view = new Uint8array (myarray);
for (var i=0; i< longint8view.length; i++) {
longint8view[i] = i% 255;
}
var xhr = new XMLHttpRequest;
Xhr.open ("POST", url, false);
Xhr.send (myarray);
Receive binary data
var oreq = new XMLHttpRequest ();
Oreq.open ("Get", "/myfile.png", true);
Oreq.responsetype = "Arraybuffer";
Oreq.onload = function (oevent) {
var arraybuffer = oreq.response;//Note:not Oreq.responsetext
if (arraybuffer) {
var bytearray = new Uint8array (arraybuffer);
for (var i = 0; i < bytearray.bytelength; i++) {
}
}
};
Oreq.send (NULL);
Of course, if the setting can only be text type, if it is a BLOB type, then the following
var oreq = new XMLHttpRequest ();
Oreq.open ("Get", "/myfile.png", true);
Oreq.responsetype = "Arraybuffer";
Oreq.onload = function (oevent) {
var blob = new Blob ([Oreq.response], {type: "Image/png"});
// ...
};
Oreq.send ();
Or
var oreq = new XMLHttpRequest ();
Oreq.open ("Get", "/myfile.png", true);
Oreq.responsetype = "blob";
Oreq.onload = function (oevent) {
var blob = oreq.response;
// ...
};
Oreq.send ();
If you are using an older version of the browser, then the load binary can be as follows
function Load_binary_resource (URL) {
var req = new XMLHttpRequest ();
Req.open (' Get ', url, false);
XHR binary charset opt by Marcus Granado 2006 [http://mgran.blogspot.com]
req.overridemimetype (' Text\/plain; Charset=x-user-defined ');
Req.send (null);
if (Req.status!=) return ";
return req.responsetext;
}
Note: X-user-defined tells the browser not to parse the data
The above is a small set to introduce the WIN7 task bar Ajax send and receive the binary Word throttling data methods related knowledge, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!