問題描述
我一直在使用同步 XMLHttpRequest 并將 responseType 設置為arraybuffer"來加載二進制文件并等待它加載.今天,我收到了這個錯誤:Die Verwendung des responseType-Attributes von XMLHttpRequest wird im synchronen Modus im window-Kontekt nicht mehr unterstützt."大致翻譯為不再支持在 window-context(?) 中以同步模式對 XMLHttpRequest 使用 responseType."
I've been using synchronous XMLHttpRequest with responseType set to "arraybuffer" for quite a while to load a binary file and wait until it is loaded. Today, I got this error: "Die Verwendung des responseType-Attributes von XMLHttpRequest wird im synchronen Modus im window-Kontekt nicht mehr unterstützt." which roughly translates to "Usage of responseType for XMLHttpRequest in synchronous mode in window-context(?) no longer supported."
有誰知道如何解決這個問題?我真的不想對這樣的事情使用異步請求.
Does anyone know how to fix this? I realy don't want to use an asynchronous request for something like this.
var xhr = new XMLHttpRequest();
xhr.open('GET', url, false);
xhr.responseType = 'arraybuffer';
在 chrome 中運行良好.
Works fine in chrome.
推薦答案
這是正確的行為,如 XMLHttpRequest的規范:
This is correct behaviour, as defined in the Specification of XMLHttpRequest:
設置時:拋出 "InvalidAccessError"
異常,如果 同步flag 已設置,并且有一個關聯的 XMLHttpRequest 文檔.
When set: throws an
"InvalidAccessError"
exception if the synchronous flag is set and there is an associated XMLHttpRequest document.
XMLHttpRequest
非異步即同步時,不能設置responseType
屬性.將open
的第三個參數設置為false
會導致請求同步.
The responseType
property cannot be set when the XMLHttpRequest
is not async, that is, synchronous. Setting the third parameter of open
to false
causes the request to be synchronous.
這篇關于突然設置 XMLHttpRequest.responseType 被禁止?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!