突然设置 XMLHttpRequest.responseType 被禁止? [英] Setting XMLHttpRequest.responseType forbidden all of a sudden?

查看:38
本文介绍了突然设置 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 被禁止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆