IndexedDB 添加条目显示成功,但未显示在 chrome 开发工具中
IndexedDB add entry shows as successful, but doesn't show up in chrome dev tools
我正在尝试编写一个简单的 JavaScript 应用程序以从 Web 表单向 indexedDB 添加一个条目。出于某种原因,添加请求显示成功,但我在 chrome 开发人员 window 中看不到任何内容,即使我刷新数据库也是如此。这是我正在写的 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 并再次打开它以使其刷新。
我正在尝试编写一个简单的 JavaScript 应用程序以从 Web 表单向 indexedDB 添加一个条目。出于某种原因,添加请求显示成功,但我在 chrome 开发人员 window 中看不到任何内容,即使我刷新数据库也是如此。这是我正在写的 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 并再次打开它以使其刷新。