我正在尝试使用XMLHttpRequest
在Javascript中检索图像数据。
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.celticfc.net/images/doc/celticcrest.png");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
var resp = xhr.responseText;
console.log(resp.charCodeAt(0) & 0xff);
}
};
xhr.send();
这些数据的第一个字节应该是
0x89
,但是任何高位字节都会返回0xfffd
(0xfffd & 0xff
为0xfd
)。像这样的问题提供了使用
overrideMimeType()
函数的解决方案,但是我正在使用的平台(Qt/QML)不支持此功能。我该如何正确下载数据?