IndexedDB不适用于Firefox 29,但适用于Chrome
我有一个问题,我已经用你的控制台在Chrome IndexedDB上开发了50%的代码。然而,要在Firefox上测试这段代码,我注意到它不起作用 异步函数不调用此JavaScript Firefox包含在HTML中:IndexedDB不适用于Firefox 29,但适用于Chrome,firefox,indexeddb,Firefox,Indexeddb,我有一个问题,我已经用你的控制台在Chrome IndexedDB上开发了50%的代码。然而,要在Firefox上测试这段代码,我注意到它不起作用 异步函数不调用此JavaScript Firefox包含在HTML中: <script src="./js/bdLocal.js"></script> 您可能正在尝试同步使用异步函数。不幸的是,Mozilla网站上的例子在这一点上是非常错误的。不幸的是,HTML5上的几个例子也是如此。以下方法在任何浏览器中都会给您带来很多问
<script src="./js/bdLocal.js"></script>
您可能正在尝试同步使用异步函数。不幸的是,Mozilla网站上的例子在这一点上是非常错误的。不幸的是,HTML5上的几个例子也是如此。以下方法在任何浏览器中都会给您带来很多问题:
var unreliableGlobalDatabaseConnectionVariable;
var request = indexedDB.open(...);
request.onsuccess = function() {
var reliableDatabaseConnectionVariable = request.result;
unreliableGlobalDatabaseConnectionVariable = reliableDatabaseConnectionVariable;
};
var transaction = unreliableGlobalDatabaseConnectionVariable.transaction(...);
// etc.
indexedDB.open是一个异步函数。这意味着很多事情,这里需要指出其中两件事:
var openDatabaseRequest = indexedDB.open(name,version);
openDatabaseRequest.onsuccess = function(event) {
console.log('Connected');
var db = openDatabaseRequest.result;
// Only access the db variable within this function
// where it is guaranteed to be defined and open
// for the scope (all statements inside) of this function. For example,
// do puts and gets and open cursors only inside this
// function.
var transaction = db.transaction(...);
var store = transaction.objectStore(...);
var request = store.put(...);
request.onsuccess = function() {
console.log('put was successful');
};
};
这个问题可能与以下问题重复:
这个问题实际上与indexedDB无关,但与Javascript中异步代码的使用有关。因此,这可能是关于使用XMLHttpRequest的数百个问题的重复。我投反对票,因为下面的实质性答案已经两周了,您还没有回答。但是,您提出了一个新问题。不需要说:请对那些花时间帮助你的人保持礼貌,并且(至少)接受/支持他们。
var openDatabaseRequest = indexedDB.open(name,version);
openDatabaseRequest.onsuccess = function(event) {
console.log('Connected');
var db = openDatabaseRequest.result;
// Only access the db variable within this function
// where it is guaranteed to be defined and open
// for the scope (all statements inside) of this function. For example,
// do puts and gets and open cursors only inside this
// function.
var transaction = db.transaction(...);
var store = transaction.objectStore(...);
var request = store.put(...);
request.onsuccess = function() {
console.log('put was successful');
};
};