0

我有一个网页应该可以离线工作,当我在本地主机上并且没有互联网连接时它可以完美运行。当我在我的服务器上托管我的页面并离线运行它(断开互联网连接)时,它会给我一个错误。

Uncaught Error: NotFoundError: DOM IDBDatabase Exception 8 
request.onsuccess

我不知道它为什么这样做。当我有互联网连接时它工作正常。我在 Firefox 和 ie10 中在线和离线进行了测试,一切正常。它也不会破坏代码,一切仍然正常,它只是向我抛出错误并且在我刷新/加载页面时没有获取数据供我渲染。这就是它抱怨的地方。

 var version = 1;
 var request = window.indexedDB.open(webDB.currentProperty, version);
 request.addEventListener('blocked', function () { console.log('blocked'); });
 console.log(webDB.currentProperty);
 request.onsuccess = function (event) {
    webDB.database = request.result;
    // make transactiona reference to the database with read option (read is the   
    default option when none is provided)       
    var transaction = webDB.database.transaction([webDB.currentProperty]);
    // hide or show elements after data has been populated 
    transaction.oncomplete = function () {
        console.log("complete");
    };
    //Get the objectstore (conatains all the object) to do things
    var objectStore = transaction.objectStore(webDB.currentProperty);

我检查了我的 chrome 版本,它是 28,我检查了当我打开数据库时是否被阻止,但我没有。

编辑

当我明确地给它一个只读选项时

var transaction = webDB.database.transaction([webDB.currentProperty], "read-only");

它引发类型错误

Uncaught TypeError: Type error
request.onsuccess
4

1 回答 1

0
  • 只读不是启动 tx 的正确类型之一。有 3 种类型,有关信息,请参阅 Mozilla 文档。
  • 我会尝试在您对 indexedDB.open 的调用中对数据库名称进行硬编码,因为您的 webDB.currentProperty 变量可能会在其他地方发生一些时髦的事情。先调试一下。
于 2013-07-27T04:57:06.573 回答