我是使用inxededdb的新手,我试图从商店中获取数据.存储包含数据,但由于某种原因,代码在尝试设置var tx后停止.如果我遗失任何内容,请告诉我.以下是我试图获取该书的功能:
原文链接:https://www.f2er.com/php/138320.htmlfunction getBook(){ var tx = db.transaction("book","readonly"); var store = tx.objectStore("book"); var index = store.index("by_getid"); var request = index.get("<?PHP echo $_GET['book'] ?>"); request.onsuccess = function() { var matching = request.result; if (matching !== undefined) { document.getElementById("text-container").innerHTML = matching.text; } else { alert('no match'); report(null); } }; }
解决版本:
function getBook(){ var db; var request = indexedDB.open("library",1); request.onsuccess = function (evt) { db = request.result; var transaction = db.transaction(["book"]); var objectStore = transaction.objectStore("book"); var requesttrans = objectStore.get(<?PHP echo $_GET['book'] ?>); requesttrans.onerror = function(event) { }; requesttrans.onsuccess = function(event) { alert(requesttrans.result.text); }; }; }