最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - IndexedDB errors in Firefox and Chrome: Unknown error and DOMException - Stack Overflow

programmeradmin0浏览0评论

I am trying to open an IndexedDB in Chrome and firefox. My code:

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: "[email protected]" },
            { id: "00-02", name: "prasad", age: 32, email: "[email protected]" }
         ];

            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);
      };

In Chrome it doesn't work at all. I get an

DOMException: The user denied permission to access the database.

In Firefox it works as shown above. However, when I change the name of the database to, say, myindexeddb, it doesn't work anymore. I get an UnknownError.

I have no idea what I am doing wrong.

I am trying to open an IndexedDB in Chrome and firefox. My code:

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: "[email protected]" },
            { id: "00-02", name: "prasad", age: 32, email: "[email protected]" }
         ];

            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);
      };

In Chrome it doesn't work at all. I get an

DOMException: The user denied permission to access the database.

In Firefox it works as shown above. However, when I change the name of the database to, say, myindexeddb, it doesn't work anymore. I get an UnknownError.

I have no idea what I am doing wrong.

Share Improve this question asked Apr 15, 2017 at 9:34 user3813234user3813234 1,6821 gold badge30 silver badges49 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

In my case, I followed these steps:

  1. Go to url chrome://settings/content in a new Chrome tab
  2. Click Cookies
  3. Uncheck Block third-party cookies

This should resolve the error.

In chrome, go to chrome://settings/content and ensure the top radio button is selected. Also check the Manage Exceptions list to see if that domain is explicitly blocked.

发布评论

评论列表(0)

  1. 暂无评论