Created
February 12, 2013 12:23
-
-
Save mohayonao/4761979 to your computer and use it in GitHub Desktop.
IE9でXMLHttpRequestを使ってバイナリファイルを読み込むやつ
This file contains hidden or 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
var path = ""; | |
var callback = function(array) { | |
console.log(array.length); | |
}; | |
var xhr = new XMLHttpRequest(); | |
xhr.open("GET", path); | |
xhr.responseType = "arraybuffer"; // IE9はこれが効かない. | |
xhr.onreadystatechange = function() { | |
if (xhr.readyState === 4) { | |
if (xhr.response) { | |
// Chrome, Firefox, Safari, Opera はこれでOK | |
callback( new Uint8Array(xhr.response) ); | |
} else if (xhr.responseBody !== undefined) { // なぜかundefinedと比較しないといけない. | |
// IE用. バイナリデータが配列に格納される. | |
callback( VBArray(xhr.responseBody).toArray() ); | |
} | |
} | |
}; | |
xhr.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment