Setting XMLHttpRequest.responseType forbidden all of a sudden?(突然设置 XMLHttpRequest.responseType 被禁止?)
问题描述
我一直在使用同步 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 被禁止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:突然设置 XMLHttpRequest.responseType 被禁止?


基础教程推荐
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01