javascript - IndexedDB 添加条目显示成功,但未显示在 chrome 开发工具中

标签 javascript google-chrome-devtools indexeddb

我正在尝试编写一个简单的 JavaScript 应用程序,以从 Web 表单向 indexedDB 添加条目。由于某种原因,添加请求显示为成功,但即使刷新数据库,我也无法在 chrome 开发人员窗口中看到任何内容。这是我正在编写的 JavaScript。

$(document).ready(function() {
    $("#addcsub").click(function(e){
        e.preventDefault();
        //add the contact
        addContact($("#clast").val(), $("#cfirst").val(), $("#cphone").val(), $("#cemail").val());
    });
});

document.addEventListener("DOMContentLoaded", function() {
    if(!"indexedDB" in window){
        return;
    }
    var openRequest = indexedDB.open("theDatabase",1);
    openRequest.onupgradeneeded = function(e) {
        var thisDB = e.target.result;

        if(!thisDB.objectStoreNames.contains("contacts")) {
            var objectStore = thisDB.createObjectStore("contacts", {keyPath:"contactid",autoIncrement: true});
            objectStore.createIndex("contactid","contactid",{unique:true});
            objectStore.createIndex("lastname","lastname", {unique:false});
            objectStore.createIndex("firstname","firstname", {unique:false});
            objectStore.createIndex("phone","phone", {unique:false});
            objectStore.createIndex("email","email", {unique:false});
        }
    }
    openRequest.onsuccess = function(e) {
        db = e.target.result;
    }
    openRequest.onerror = function(e) {
        console.log("Open Request Error");
    }
},false);

function addContact(last,first,phone,email){
    var transaction = db.transaction(["contacts"],"readwrite");
    var store = transaction.objectStore("contacts");
    var tc = {
        lastname:last,
        firstname:first,
        phone:phone,
        email:email
    }
    var request = store.add(tc);

    request.onerror = function(e){
        console.error(request.error);
    }
    request.onsuccess = function(e){ //this runs when I hit submit
        console.log("Add Successful"); //this appears in the console
    }

}

更新:我做了一些研究,发现我的添加事务正在中止,并出现 DOMException 代码 22 的错误。

更新 2:由于某种原因,它可以在其他计算机上运行,​​但不能在我的笔记本电脑上运行。

最佳答案

我在使用 indexedDb 时遇到了 devtools gui 的问题。您可以尝试通过控制台拉出记录,看看它是否存在,但在过去,我必须关闭开发工具并再次打开它才能刷新。

关于javascript - IndexedDB 添加条目显示成功,但未显示在 chrome 开发工具中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47521254/

相关文章:

javascript - ajax 根据从 URL 发送的 Json 对象执行操作

javascript - 忽略正则表达式中的常规 HTML 标签

javascript - 尝试使用资源响应作为所选项目时 ngOptions 的奇怪行为

javascript - 从 Firebug/Chrome 控制台与 require.js 模块交互?

javascript - 如何将回调传递给全局 onerror 方法?

javascript - 在不破坏现有保存的情况下更改保存的应用程序数据格式的策略 (JavaScript+IndexedDB)

indexeddb - 索引数据库是否进行并行处理?

javascript - 使用 Spring Boot 和 Zuul 进行 CORS 预检请求的 Host 与 Origin header

javascript - 如何计算 Javascript 的带宽使用量?

javascript - Puppeteer:如何根据文本选择下拉选项?