var req = new XMLHttpRequest();
req.open(‘GET’, url, false);
//XHR binary charset opt by Marcus Granado 2006 [http://mgran.blogspot.com]
req.overrideMimeType(‘text/plain; charset=x-user-defined’);
try {
req.send(null);
if (req.status != 200) return ”;
//*bugfix* by Marcus Granado 2006 [http://mgran.blogspot.com] adapted by Thomas Belot
var out = ”;
for(i=0;i<req.responseText.length;i++){
out+=String.fromCharCode(req.responseText.charCodeAt(i) & 0xff);
//out+=req.responseText.charCodeAt(i) & 0xff;
}
return out;
}catch (e){
this.DEBUG(‘loadBinaryResource: failednException:’+e);
}
参考资料:
» [译] JavaScript (XMLHttpRequest) 读取二进制数据流 » JavaScript » bianbian coding life
JavaScript (XMLHttpRequest) 读取二进制数据流
mgran’s ars technica: Downloading Binary Streams with Javascript XMLHttpRequest