I am trying to download an image by ajax (for some reasons i will not explain here).
But i am getting all 127-255 bytes seted to 65533.
Example:
From the image
Which tells the browser: Don't treat it as characters. Don't treat it as anything. Just pass it through.
Now you should be seeing different, but still large, numbers. It seems that an 0xF7 byte will be in the high-order position. I couldn't find any explanation why this happens, but nonetheless we can remove it with a second piece of magic:
Looks like you need to use VBScript if it's ever going to work in IE. It gets pretty ugly. But fortunately someone wrapped the ugliness in a library.
You can read the source if you're curious what's going on under the hood. Otherwise, just go ahead and load the library into your page and use its API.
Code:
<script type="text/javascript" src="http://www.heypage.com/nagoon97/BinFileReader/BinFileReader.js"></script>
<script type="text/javascript">
var bmpFile = new BinFileReader("Icon.bmp");
document.body.appendChild(document.createTextNode("Size: " + bmpFile.getFileSize()));
document.body.appendChild(document.createElement("br"));
for (var i = 0; i < bmpFile.getFileSize(); i++) {
document.body.appendChild(document.createTextNode(" " + bmpFile.readString(1, i).charCodeAt(0)));
}
</script>
I have tried and it run well. I also discovered that it's possible to read directly in the correct charset without the conversion byte to byte ( & 0xff ) changing only that line:
Bookmarks