我必须承认我对indexedDB非常陌生。
我写了一段简单的indexedDB代码,如下所示:
i must admit that i am very new to indexedDB
I wrote a simple code of indexedDB
and it is as followed:
function go() {
var req = window.indexedDB.open("Uploader", 1),
db;
req.onerror = function (e) {
console.log("Error");
};
req.onsuccess = function (e) {
db = e.target.result;
};
req.onupgradeneeded = function (e) {
console.log(db);
db = e.target.result;
var os = db.createObjectStore("Files", { keyPath: "files" });
os.createIndex("text", "text_file", { unique: false });
var trans = db.transaction(["text"], "readwrite");
var objectstore = trans.objectStore("text");
var addreq = objectstore.add("Instructions.js");
addreq.onsuccess = function (e) {
console.log("Success!");
console.dir(e);
};
};
}
它给出的错误是Uncaught InvalidStateError: Failed to execute 'transaction' on 'IDBDatabase': A version change transaction is running.
它说正在运行一个版本更改事务A version change Transaction is running
,但据我所学,版本更改事务是通过IDBFactory.open
方法创建的,并且我没有使用它。我已经指定了这个事务是readwrite
并且在onupgradeneeded
中,那么为什么会出现错误呢?
我必须承认我对indexedDB非常陌生。
Uncaught NotFoundError: Failed to execute 'objectStore' on 'IDBTransaction': The specified object store was not found.
在行transaction.objectStore('text')
。 - anni sainidb.transaction
不起作用,但event.target.transaction
可以。 - oomer