2017-04-15 1 views
0

ChromeとFirefoxでIndexedDBを開こうとしています。私のコード:FirefoxとChromeのIndexedDBエラー:不明なエラーとDOMException

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

クロムでは全く動作しません。私は

DOMException: The user denied permission to access the database. 

上記のように動作します。しかし、データベースの名前をたとえばmyindexeddbに変更しても、それはもう機能しません。私はUnknownErrorを得る。

私は何が間違っているのか分かりません。

答えて

1

クロムの場合、chrome:// settings/contentに移動し、上部のラジオボタンが選択されていることを確認します。また、[例外の管理]リストをチェックして、そのドメインが明示的にブロックされているかどうかを確認します。

関連する問題