未捕获错误:NotFoundError:DOM IDBDatabase异常8(脱机)

时间:2013-07-26 23:39:28

标签: indexeddb offline-caching

我有一个网页,假设能够脱机工作,当我在localhost上并且没有互联网连接时它完美无缺。当我在我的服务器上托管我的页面并离线运行(断开互联网)时,它会抛出一个错误。

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

1 个答案:

答案 0 :(得分:0)

  • 只读不是启动tx的正确类型之一。有3种类型,请参阅mozilla文档以获取信息。
  • 我会尝试在你对indexedDB.open的调用中硬编码db名称,因为在其他地方你的webDB.currentProperty变量可能会发生一些时髦的事情。先调试一下。