【问题标题】:"InvalidStateError: A mutation operation was attempted on a database that did not allow mutations."“InvalidStateError:在不允许突变的数据库上尝试了突变操作。”
【发布时间】:2018-07-24 19:35:35
【问题描述】:

我正在尝试在 then() 中打开一个事务。它给了我异常。 代码如下:

open.onsuccess = function (e1) {
 var dbase = e1.target.result;
$.get("https://www.uuidgenerator.net/api/version4").then(
        function (message) {
            debugger;
            var projectData = { "uid": message, "name": "appName", "pages": [] };
            var trans = dbase.transaction(["Project"], "readwrite"); // error over here
            var store = trans.objectStore("Project");
            var projectAddReq = store.add(projectData);
            projectAddReq.onsuccess = function (e) {
                console.log("added project name into the database");
            }
            projectAddReq.onerror = function (e) {
                console.log("error adding project name into the database");
            }
        });
}

谁能帮帮我,为什么会出现错误?

【问题讨论】:

    标签: javascript ajax promise indexeddb


    【解决方案1】:

    尝试在获取后打开与数据库的连接,而不是使用在不同时间实例化的 IDBDatabase 变量。

    【讨论】:

    • 我认为可以调查这个link。
    • 这是可能的,但如果你已经感到困惑,我建议现在以保证工作的安全方式进行
    猜你喜欢
    • 1970-01-01
    • 2013-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-03
    • 1970-01-01
    • 2011-03-01
    • 2019-06-18
    相关资源
    最近更新 更多