Javascript 为什么indexedDB给出了无效的状态错误?

Javascript 为什么indexedDB给出了无效的状态错误?,javascript,indexeddb,Javascript,Indexeddb,当我运行此代码时: var idbSupported = false; var db; document.addEventListener("DOMContentLoaded", function(){ if("indexedDB" in window) { idbSupported = true; } if(idbSupported) { var openRequest = indexedDB.open("test",1);

当我运行此代码时:

var idbSupported = false;
var db;

document.addEventListener("DOMContentLoaded", function(){

    if("indexedDB" in window) {
        idbSupported = true;
    }

    if(idbSupported) {
        var openRequest = indexedDB.open("test",1);

        openRequest.onupgradeneeded = function(e) {
            console.log("Upgrading...");
        }

        openRequest.onsuccess = function(e) {
            console.log("Success!");
            db = e.target.result;
        }

        openRequest.onerror = function(e) {
            console.log("Error: " + e.target.errorCode);
            // console.dir(e);
        }

    }

},false);
从本教程中:

在Firefox17中

不知道为什么我得到的是错误事件而不是成功事件

简化的代码给出了相同的错误:(只需复制粘贴)请参见控制台

(function(){
    if(window.indexedDB) {
        var openRequest = indexedDB.open("test", 1);
        openRequest.onupgradeneeded = function(e) {
            console.log("Upgrading...");
        }
        openRequest.onsuccess = function(e) {
            console.log("Success!");
            db = e.target.result;
        }
        openRequest.onerror = function(e) {
            console.log("Error: " + e.target.errorCode);
            console.dir(e);
        }
    }
})();
根据,FF 16及以上版本不需要前缀


我注意到的一点是,浏览器没有要求获得使用indexedDB的权限,因为它应该这样做,所以可能浏览器没有配置为使用indexedDB?

可能尝试更高版本号,可能数据库allready存在于更高版本中。或者只打开没有版本号的数据库。指数开放(“测试”);b、 c.它依赖于域,我设置了域号,可能性不大,但会尝试使用域号。但是indexedDB应该提示用户请求权限,但它没有。我认为这是一个更大的疑点。我不是100%确定,但我认为Firefox中第一个未经修复的indexeddb版本存在一些问题。也许试试FF 18,看看你是否还有这个问题。我之所以放弃这个问题,是因为我放弃了HTML5应用程序存储,它可能会打断用户的权限,让用户产生妄想症。