gpt4 book ai didi

javascript - Firefox 和 Chrome 中的 IndexedDB 错误 : Unknown error and DOMException

转载 作者:行者123 更新时间:2023-12-03 04:32:39 26 4
gpt4 key购买 nike

我正在尝试在 Chrome 和 Firefox 中打开 IndexedDB。我的代码:

var v = 2;
var request = indexedDB.open("orders", v);


//Firefox code for db init
request.onupgradeneeded = function (e) {

console.log("onupgradeneeded");
var db = e.target.result;
// We can only create Object stores in a setVersion transaction;

if(db.objectStoreNames.contains("client")) {
var storeReq = db.deleteObjectStore("client");
}

const employeeData = [
{ id: "00-01", name: "gopal", age: 35, email: "gopal@tutorialspoint.com" },
{ id: "00-02", name: "prasad", age: 32, email: "prasad@tutorialspoint.com" }
];

var objectStore = db.createObjectStore("client", {keyPath: "id"});

for (var i in employeeData) {
objectStore.add(employeeData[i]);
}

}

request.onsuccess = function(e) {
var db = e.target.result;

console.log("Success");
console.log(db);


var transaction = db.transaction(["client"]);
var objectStore = transaction.objectStore("client");
var request = objectStore.get("00-02");

request.onerror = function(event) {
alert("Unable to retrieve daa from database!");
};

request.onsuccess = function(event) {
// Do something with the request.result!
if(request.result) {
alert("Name: " + request.result.name + ", Age: " + request.result.age + ", Email: " + request.result.email);
}

else {
alert("Kenny couldn't be found in your database!");
}
};


};

request.onerror = function(e) {
console.log(e);
};

在 Chrome 中它根本不起作用。我得到一个

DOMException: The user denied permission to access the database.

在 Firefox 中,其工作原理如上所示。但是,当我将数据库名称更改为 myindexeddb 时,它就不再起作用了。我收到 UnknownError

我不知道我做错了什么。

最佳答案

就我而言,我按照以下步骤操作:

  1. 在新的 Chrome 标签页中转到网址 chrome://settings/content
  2. 点击Cookie
  3. 取消选中阻止第三方 cookie

这应该可以解决错误。

关于javascript - Firefox 和 Chrome 中的 IndexedDB 错误 : Unknown error and DOMException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43424487/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com