【问题标题】:InvalidStateError - Kendo UI UploadInvalidStateError - Kendo UI 上传
【发布时间】:2018-05-29 16:34:48
【问题描述】:

我不断收到这个奇怪的错误,当我尝试设置我的授权标头时,我不断收到“InvalidStateError”。这是我的代码:

$("#files").kendoUpload({
                        async: {
                            saveUrl: myApiUrl + "/" + id,
                            autoUpload: true
                        },
                        upload: function(e) {
                            var xhr = e.XMLHttpRequest;
                            if (xhr) {
                                xhr.addEventListener("readystatechange", function onReady(e) {
                                    if (xhr.readyState === 1 /* OPENED */) {
                                            xhr.setRequestHeader("Authorization", "Bearer " + accessToken);
                                    }
                                });
                            }
                        }
                    });

【问题讨论】:

    标签: kendo-ui kendo-upload


    【解决方案1】:

    事实证明,IE 出于某种原因为 readyState==1 触发了两次 readystatechange。我不知道为什么,但确实如此。它第二次调用它使其抛出错误。所以这是我的解决方案:

    第一次调用后,我只是删除了监听器。

    $("#files").kendoUpload({
                            async: {
                                saveUrl: myApiUrl + "/" + id,
                                autoUpload: true
                            },
                            upload: function(e) {
                                var xhr = e.XMLHttpRequest;
                                if (xhr) {
                                    xhr.addEventListener("readystatechange", function onReady(e) {
                                        if (xhr.readyState === 1 /* OPENED */) {
                                            xhr.setRequestHeader("Authorization", "Bearer " + accessToken);
                                            xhr.removeEventListener("readystatechange", onReady);
                                        }
                                    });
                                }
                            }
                        });
    

    【讨论】:

      猜你喜欢
      • 2019-02-19
      • 1970-01-01
      • 2014-03-09
      • 1970-01-01
      • 1970-01-01
      • 2017-04-01
      • 1970-01-01
      • 2018-09-03
      • 2021-08-13
      相关资源
      最近更新 更多