设置 HttpRequest 的响应类型

set responseType of a HttpRequest

我想这样做:

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