gpt4 book ai didi

javascript - 设置 HttpRequest 的响应类型

转载 作者:行者123 更新时间:2023-12-03 07:39:39 26 4
gpt4 key购买 nike

我想这样做:

function loadSound(url) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';

// Decode asynchronously
request.onload = function() {
context.decodeAudioData(request.response, function(buffer) {
sound= buffer;
}, onError);
}
request.send();
}

但是我收到了这个错误:

Uncaught InvalidAccessError: Failed to set the 'responseType' property on 'XMLHttpRequest': The response type cannot be changed for synchronous requests made from a document.

有什么建议吗?

最佳答案

这是规范定义的内容:

Note: Starting with Gecko 11.0 (Firefox 11.0 / Thunderbird 11.0 / SeaMonkey 2.8), as well as WebKit build 528, these browsers no longer let you use the responseType attribute when performing synchronous requests. Attempting to do so throws an NS_ERROR_DOM_INVALID_ACCESS_ERR exception. This change has been proposed to the W3C for standardization.

来自:https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

关于javascript - 设置 HttpRequest 的响应类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35461158/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com