![](/img/trans.png)
[英]InvalidStateError: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing with ios safari
[英]Failed to execute 'createObjectStore' on 'IDBDatabase'
为什么我有错误?
我的代码:
var idb = window.indexedDB || // Use the standard DB API
window.mozIndexedDB || // Or Firefox's early version of it
window.webkitIndexedDB; // Or Chrome's early version
var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;
var IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange;
var dbName='nameDb';
var idbRequest=idb.open(dbName,'4.67' /*,dbDescription */);
idbRequest.onsuccess=function (e) {
debugger
var db=e.target.result;
if (!db.objectStoreNames.contains('chat')){
co=db.createObjectStore('chat',{'id':100});
};
if (!db.objectStoreNames.contains('iam')){
co1=db.createObjectStore('iam');
};
};
idbRequest.onerror = function (e) {
debugger
};
未捕获的 InvalidStateError:无法在“IDBDatabase”上执行“createObjectStore”:数据库未运行版本更改事务。 index.html:37 idbRequest.onsuccess
您不能创建一个objectStore
在一个onsuccess
方法。 您只能在upgradeneeded
事件中执行此upgradeneeded
。
来自文档的引用:
当您创建新数据库或增加现有数据库的版本号时(通过指定比以前更高的版本号,在打开数据库时),将触发
onupgradeneeded
事件。 在此事件的处理程序中,您应该创建此版本数据库所需的对象存储
请参阅文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.