问题描述
我一直在使用同步 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设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)