Created
July 4, 2012 20:36
-
-
Save cburgmer/3049436 to your computer and use it in GitHub Desktop.
Reading a binary file through AJAX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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