I am trying to read a binary file MyFile.xxx that is at the same domain as MyFile.html. Using JQuery I just try to display an alert with the number of characters in MyFile.xxx, and print the numeric representation of each one. However, I get different results depending on the browser:
Google Chrome: I correctly get an alert displaying 33, and the correct integers
Firefox: Alert displays “Undefined” and no integers are printed.
IE9: Alert displays “1” and no integers are printed.
Any ideas? Thanks
MyFile.html
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$.get('/MyFile.xxx', function(a){
var l=a.length,x=[l];
alert(l);
for(i=0;i<l;i++){
x[i]=a[i].charCodeAt(0);
document.write(x[i]);
document.write("<br>");
}
});
</script>
</head>
<body>
</body>
</html>
Try this:
Demo: http://jsfiddle.net/SXgfu/ (Shows the UTF-8 bytes for
åöä)Note that IE9 does not support this. It does not support any other ways of getting raw bytes of the response either.
If you are using PHP, you could use this work-around for IE:
Where
base64encoder.phpis something like:remember to sanitize the above, otherwise it’s a huge security vulnerability
and
decode64(src http://ntt.cc/2008/01/19/base64-encoder-decoder-with-javascript.html):