Skip to content

Instantly share code, notes, and snippets.

@cburgmer
Created July 4, 2012 20:36
Show Gist options
  • Save cburgmer/3049436 to your computer and use it in GitHub Desktop.
Save cburgmer/3049436 to your computer and use it in GitHub Desktop.
Reading a binary file through AJAX
// See https://developer.mozilla.org/en/DOM/XMLHttpRequest/Sending_and_Receiving_Binary_Data
var readBinaryFile = function (url) {
var content, newContent = "";
$.ajax({
dataType: 'text',
mimeType: 'text/plain; charset=x-user-defined',
url: url,
async: false,
cache: false,
success: function (theContent) {
for (var i = 0; i < theContent.length; i++) {
newContent += String.fromCharCode(theContent.charCodeAt(i) & 0xFF);
}
content = newContent;
}
});
return content;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment