设置XMLHttpRequest.responseType突然禁止? [英] Setting XMLHttpRequest.responseType forbidden all of a sudden?
问题描述
我一直在使用同步XMLHttpRequest,responseType设置为arraybuffer很长一段时间来加载一个二进制文件并等待加载。今天,我得到了这个错误:
Die Verwendung des responseType-Attributes von XMLHttpRequest wird im synchronen Modus im window-Kontekt nicht mehrunterstützt。
大致转换为
不再支持window-context(?)同步模式下的XMLHttpRequest对responseType的使用。
有没有人知道如何解决这个问题?我真的不想使用这样的异步请求。
var xhr = new XMLHttpRequest();
xhr.open('GET',url,false);
xhr.responseType ='arraybuffer';
在Chrome中正常工作。解决方案
这是正确的行为,如 XMLHttpRequest的规范:
lockquote
设置时:抛出一个 InvalidAccessError
http://www.w3.org/TR/XMLHttpRequest/#synchronous-flagrel =noreferrer> 同步
标志,并且有一个关联的<一个href =http://www.w3.org/TR/XMLHttpRequest/#xmlhttprequest-document =noreferrer> XMLHttpRequest文档。
当 XMLHttpRequest
不是异步时, responseType
属性不能被设置, ,同步。将打开
的第三个参数设置为 false
会导致请求同步。
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';
Works fine in chrome.
This is correct behaviour, as defined in the Specification of XMLHttpRequest:
When set: throws an
"InvalidAccessError"
exception if the synchronous flag is set and there is an associated XMLHttpRequest document.
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突然禁止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!