更新indexedDB数据

时间:2014-02-17 06:44:00

标签: indexeddb

我正在尝试更新索引的数据库数据。我所做的就是这个..

    function update_doc() {
    var id = document.getElementById("txt_id").value;
    var name = document.getElementById("txt_name").value;
    console.log("About to update " + id + "/" + name);
    var transaction = db.transaction(["stud_store"], "readwrite");
    var store = transaction.objectStore("stud_store");
    var stud = {
        id: id,
        name: name,
        created: new Date()
    }
    var putresult = store.put(stud);
    putresult.onsuccess = function (e) {
        alert("Successfully Done...!");
        console.log("Woot! Did it");
    };
    putresult.onerror = function (e) {
        alert("Something is wrong (Error name: " + e.target.error.name + "  Error message: " + e.target.error.message + ").");
        console.log("Error", e.target.error.id);
        console.dir(e.target);
    }
}

(其中id是唯一的)我收到以下错误...

enter image description here

1 个答案:

答案 0 :(得分:-1)

您是否忘了打开数据库?

var request = window.indexedDB.open("MyDatabase", 3);

docs - https://developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB

显示如何创建和打开数据库的更多代码可能有所帮助。