我試圖獲得與XMLHttpRequest
gltf二進制文件。這是我試過的代碼。爲什麼JavaScript XMLHttpRequest八位字節流MIME類型返回字符串的響應?
var xhr = new XMLHttpRequest();
xhr.open("GET","THE ADDRESS",true);
xhr.setRequestHeader("Accept", "application/octet-stream");
xhr.responseType = "arraybuffer";
xhr.onload = function (v) {
resolve(xhr.response); // xhr.response must be ArrayBuffer but xhr.response is string
};
xhr.onerror = function (e) {
reject(e);
};
xhr.send();
如根據上面的代碼中,我肯定設置的responseType爲arraybuffer
。但是,當負載處理程序調用時,responseType
字段被更改爲""
。
我沒有在這段代碼中調用任何其他``XMLHttpRequest。這是我得到的響應標題。
accept-ranges:bytes
content-length:102040
content-type:application/octet-stream
date:Fri, 18 Nov 2016 09:30:13 GMT
etag:"582ec3ef-18e98"
last-modified:Fri, 18 Nov 2016 09:03:43 GMT
server:h2o/2.0.4
status:200
而這是我發送的請求標題。
:authority:localhost
:method:GET
:path:/gex/t90-01/Duck/Duck.bin
:scheme:https
accept:*/*
accept-encoding:gzip, deflate, sdch, br
accept-language:ja,en-US;q=0.8,en;q=0.6
cache-control:no-cache
pragma:no-cache
referer:https://localhost/gex/
user-agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
Anyt help?
如何驗證數據類型?你用'typeof'嗎? –
我在檢查員身上檢查過它。我看到''response'字段是用'''括起來的,所以我認爲它是字符串。「 – kyasbal
爲了防萬一,我用'typeof'對其進行了檢查,但實際上這是字符串 – kyasbal