Skip to content

Instantly share code, notes, and snippets.

@fujidig
Created March 21, 2014 08:00
Show Gist options
  • Save fujidig/9681642 to your computer and use it in GitHub Desktop.
Save fujidig/9681642 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>binary-test.html</title>
<script src="http://code.jquery.com/jquery-2.1.0.js"></script>
<script>
function loadBinary(url) {
var xhr = new XMLHttpRequest;
var deferred = jQuery.Deferred();
xhr.open("GET", url);
xhr.responseType = "arraybuffer";
xhr.onreadystatechange = function () {
if (this.readyState != 4) return;
if (this.status == 200) {
deferred.resolveWith(this, [this.response]);
} else {
deferred.rejectWith(this);
}
};
xhr.send(null);
return deferred.promise();
}
$(function() {
loadBinary("t.ax").done(function(b) {
alert(b.byteLength);
});
});
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment