下面是我的代碼。它第一次運行良好,但一旦我刷新頁面,它會產生未捕獲的TypeError:無法調用未定義的方法'事務'。索引DB中的「無法調用未定義的」錯誤的方法'事務'
基本上我從數據從數據庫中檢索,並對其進行編碼成可用的JSON數據類型,以避免插入問題納入我的表。
$(document).ready(function() {
//prefixes of implementation that we want to test
window.indexedDB = window.indexedDB ||
window.mozIndexedDB ||
window.webkitIndexedDB ||
window.msIndexedDB;
//prefixes of window.IDB objects
window.IDBTransaction = window.IDBTransaction ||
window.webkitIDBTransaction ||
window.msIDBTransaction;
window.IDBKeyRange = window.IDBKeyRange ||
window.webkitIDBKeyRange ||
window.msIDBKeyRange
if(!window.indexedDB){ //alert user if browser does not support
window.alert("Your browser doesn't support a stable version of IndexedDB.")
}
var request = window.indexedDB.open("runningClub", 1); //create a runningClub database
var browserDB;
request.onsuccess = function(event){
browserDB = request.result;
};
var raceIDs = [];
$(".raceID").each(function() {
raceIDs.push(" raceID = " + $(this).val());
});
$.ajax({
url: 'controller/AJAX/userAction.php',
type: 'post',
dataType: 'json',
data: { statement : "getRaceResult", raceIDs : raceIDs },
success: function(data) {
const results = data;
request.onupgradeneeded = function(event){
var browserDB = event.target.result;
var objectStore = browserDB.createObjectStore("raceResult", {keyPath: "resultID"});
for(var i in results){
objectStore.add(results[i]);
}
}
var objectStore = browserDB.transaction("raceResult").objectStore("raceResult");
objectStore.openCursor().onsuccess = function(event){
var cursor = event.target.result;
if (cursor){
$("#memberName").append("<option>" + cursor.value.memberName + "</option>");
cursor.continue();
}
};
}
});
});
後端是somethign這樣的: 情況下 'getRaceResult': \t \t \t $ \t raceResults = $用戶> getAllRaceResult($ raceIDs); \t \t \t \t echo json_encode($ raceResults); \t \t \t \t break; – Michael
粘貼失敗,但刪除「const」關鍵字,替換爲'var',併爲我開一槍。 – buley
PHP,酷,我完全遵循 - 但我需要'$ raceResults'的值。我所要做的是確認您的數據可存儲。 IDB無法存儲所有類型的JavaScript數據。 – buley