【问题标题】:set responseType of a HttpRequest设置 HttpRequest 的 responseType
【发布时间】:2016-05-29 10:05:14
【问题描述】:

我想这样做:

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();
}

但是我收到了这个错误:

未捕获的 InvalidAccessError:无法在“XMLHttpRequest”上设置“responseType”属性:无法更改从文档发出的同步请求的响应类型。

有什么建议吗?

【问题讨论】:

    标签: javascript xmlhttprequest


    【解决方案1】:

    这是规范定义的:

    注意:从 Gecko 11.0 (Firefox 11.0 / Thunderbird 11.0 / SeaMonkey 2.8) 以及 WebKit build 528 开始,这些浏览器不再允许您在执行同步请求时使用 responseType 属性。尝试这样做会引发 NS_ERROR_DOM_INVALID_ACCESS_ERR 异常。此更改已提交给 W3C 进行标准化。

    发件人:https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

    【讨论】:

    猜你喜欢
    • 2019-01-18
    • 2019-05-06
    • 2022-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-02
    • 1970-01-01
    相关资源
    最近更新 更多