JSFiddle - React, Tailwind, and code Playground
JavaScript
// Method 1: Native XMLHttpRequest arraybuffer
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://g.etfv.co/http://www.google.com', true);
xhr.responseType = 'arraybuffer';
xhr.onload = function (e) {
var arrayBuffer = xhr.response;
if (arrayBuffer) {
var byteArray = new Uint8Array(arrayBuffer);
console.log('With XMLHttpRequest', byteArray.byteLength, byteArray);
for (var i = 0; i < byteArray.byteLength; i++) {
// do something with each byte in the array
}
}
};
xhr.send(null);
// Method 2: jQuery using charset hack
$.ajax({
url: 'http://g.etfv.co/http://www.google.com',
beforeSend: function (xhr) {
xhr.overrideMimeType('text/plain; charset=x-user-defined');
}
}).done(function (data) {
var byteArray = [];
for (var i = 0; i < data.length; i++) {
byteArray.push(data.charCodeAt(i) & 0xff);
}
console.log('With jQuery', byteArray.length, byteArray);
});