草庐IT

javascript - "An IndexedDB transaction that was not yet complete has been aborted due to page navigation"

coder 2024-05-12 原文

我正在使用 IndexedDB 来存储一些数据。它似乎有效,但如果我刷新页面,我会在 Firefox (36.0.4) 的浏览器控制台中看到:尚未完成的 IndexedDB 事务已因页面导航而中止。。我正在使用这个(本地)文件进行测试:

<html>
  <head><meta charset="UTF-8"></head>
  <body>
    <script>
var request = window.indexedDB.open("test_db", 2);
request.onupgradeneeded = function (event) {
  request.result.createObjectStore("test_store");
};

request.onsuccess = function (event) {
  var db = request.result;
  var transaction = db.transaction(["test_store"], "readwrite");
  var put = transaction.objectStore("test_store").put("key", "value");
  transaction.oncomplete = function (event) {
    console.log("Transaction complete");
  };
};
    </script>
  </body>
</html>

如果我执行多个事务,我会收到多个错误。如果我有一个执行事务的 onclick 处理程序,并且我点击了它几次,刷新会为我过去进行的每个事务打印一个错误。

所有这些让我觉得我的交易没有被清理。我需要做什么才能完成交易?

正在调用我的 oncomplete 处理程序。刷新几次,浏览器控制台是这样的:

"Transaction complete" test.html:16:1
An IndexedDB transaction that was not yet complete has been aborted due to page navigation. test.html:13:0
"Transaction complete" test.html:16:1
An IndexedDB transaction that was not yet complete has been aborted due to page navigation. test.html:13:0
"Transaction complete" test.html:16:1

测试页面(Ctrl-Shift-J 打开控制台,然后 Ctrl-R 刷新显示错误):

http://test.roscidus.com/static/idb.html

最佳答案

错误was a bug in Firefox ,现在它已经修复了:

Status: RESOLVED FIXED

修复已在 Firefox 41 上完成,which was released on Sep 22th 2015 .

Tracking Flags: status-firefox41: fixed

关于javascript - "An IndexedDB transaction that was not yet complete has been aborted due to page navigation",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29242346/

有关javascript - "An IndexedDB transaction that was not yet complete has been aborted due to page navigation"的更多相关文章

随机推荐