gpt4 book ai didi

javascript - 使用 IndexedDB 创建多个对象存储时,Safari 7.1 中出现 UnknownError

转载 作者:行者123 更新时间:2023-11-28 00:50:02 25 4
gpt4 key购买 nike

我想进行健全性检查,看看是否有其他人在使用 Safari 7.1 和 IndexedDB 时遇到问题。似乎我收到了 UnknownError 类型的错误,根据 http://www.w3.org/TR/IndexedDB/ 的规范当“操作因与数据库本身无关且未被任何其他错误涵盖的原因而失败”时发生。在第一次调用调用回调(onSuccess 或 onError)之后,我第二次调用此函数时会发生这种情况。这是我创建对象存储的函数,它适用于 Chrome 和 Firefox。

IndexedDBClient.prototype.createObjectStore = function(options) {
if (this.checkIfObjectStoreExists(options.objectStoreName)) {
options.onError(this.objectStoreDNEMessage);
return;
}

var objectStore;

var objectStoreCreated = false;
var databaseOpened = false;

var version = this.database.version;
var dbName = this.database.name;
this.database.close();
var request = indexedDB.open(dbName, ++version);
var that = this;

request.onupgradeneeded = function(e) {
that.database = e.target.result;
objectStore = that.database.createObjectStore(options.objectStoreName, { keyPath: options.keyPathName });

objectStore.transaction.oncomplete = function(e) {
objectStoreCreated = true;
successCallback();
}

objectStore.transaction.onerror = function(e) {
options.onError(e);
};
};

request.onsuccess = function(e) {
databaseOpened = true;
successCallback();
}

request.onerror = function(e) {
options.onError(e);
};

request.onblocked = function(e) {
typeof options.onBlocked === 'function' && options.onBlocked();
};

function successCallback() {
// This is needed because we must be sure that both the objectstore creation transaction has completed,
// and the db open request has fired the onsuccess event.
objectStoreCreated && databaseOpened && options.onSuccess(objectStore);
}
};

最佳答案

Safari 浏览器中的 IndexedDB API 有 bug多个商店交易。

关于javascript - 使用 IndexedDB 创建多个对象存储时,Safari 7.1 中出现 UnknownError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26899035/

25 4 0
文章推荐: javascript - WordPress 强制脚本在插件之后加载
文章推荐: javascript - JS - 如何仅在已经切换的情况下切换 CSS 类
文章推荐: javascript - 如何创建自定义