尝试创建事务时出现DOM IDBDatabase异常11
DOM IDBDatabase Exception 11 when trying to create a transaction
我使用的是最新的谷歌chrome。。我正在尝试实现HTML5索引数据库示例。AIM是在页面加载并存储数据时创建数据库。如果有任何示例,请发布任何示例。我尝试过这个代码,但当我尝试创建事务时,得到了Uncaught Error: InvalidStateError: DOM IDBDatabase Exception 11
。这是代码片段。。
var idbRequest;
var idb;
$(document).ready(function(){
//ini----------------------
var peopleData = [
{ name: "John Dow", email: "john@company.com" },
{ name: "Don Dow", email: "don@company.com" }
];
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB;
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange;
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;
//create database.............
if (window.indexedDB) {
idbRequest = window.indexedDB.open("StoreDB");
idbRequest.onsuccess = function(e) {
idb = idbRequest.result || e.result; // FF4 requires e.result. IDBRequest.request isn't set :(
/*idbRequest.onerror = function (evt) {
console.log("IndexedDB error: " + evt.target.errorCode);
};*/
var v = '2.0';
var setVrequest = idb.setVersion(v);
setVrequest.onsuccess = function(e) {
if(idb.objectStoreNames.contains("Stores")) {
alert("ObjectStore is already created.");
return false;
}
var objectstore = idb.createObjectStore("Stores");
alert("Object store Created.");
if (!idb.objectStoreNames.contains('Stores')) {
alert("Object store doesn't exist.");
return;
}else{
alert("Object store contain 'store'");
}
// Create a transaction that locks the world.
var trans = idb.transaction(["Stores"],"readwrite");//getting exception on this line..
trans.oncomplete = function(){
console.log("Success transaction");
};
var objectStore = trans.objectStore("Stores");
var request = objectStore.put(
1,
"wsdsdsd");
alert("data added");
};
};
}
});
已解决。。我遇到错误,因为在版本更改过程中无法创建事务。。这是最后一个可行的答案。。
var idbRequest;
var idb;
$(document).ready(function(){
//ini----------------------
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB;
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange;
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;
//create database.............
if (window.indexedDB) {
idbRequest = window.indexedDB.open("DB");
idbRequest.onsuccess = function(e) {
idb = idbRequest.result || e.result; // FF4 requires e.result. IDBRequest.request isn't set :(
/*idbRequest.onerror = function (evt) {
console.log("IndexedDB error: " + evt.target.errorCode);
};*/
var v = '2.0';
var setVrequest = idb.setVersion(v);
setVrequest.onsuccess = function(e) {
if(idb.objectStoreNames.contains("Stores")) {
alert("ObjectStore is already created.");
var vertrans = setVrequest.result;
vertrans.oncomplete = doStuff;
return false;
}
var objectstore = idb.createObjectStore("Stores");
alert("Object store Created.");
if (!idb.objectStoreNames.contains('Stores')) {
alert("Object stores doesn't exist.");
return;
}else{
alert("Object store contain 'stores'");
}
var vertrans = setVrequest.result;
vertrans.oncomplete = doStuff;
};
};
}
});
function doStuff(){
// Create a transaction that locks the world.
var trans = '';
trans = idb.transaction(['Stores'],'readwrite');
var objectStore = trans.objectStore('Stores');
var request = objectStore.put(
1,
"wsdsdsd");
alert("data added");
trans.oncomplete = function(){
console.log("Success transaction");
};
}
您可以在我的网站上找到一个有效的indexeddb示例。我正在使用一个为indexeddb API编写的名为linq2indexeddb的库。尝试一下,它将为您节省大量精力,使您的代码与跨浏览器兼容。
相关文章:
- 在单击任何位置时隐藏元素,而不检查每次DOM单击
- 是否有任何snippet或jQuery插件可以列出easylist.txt模式匹配的DOM中的所有元素
- 在不使用JQuery的情况下隐藏DOM中的选定元素
- 如何在DOM元素上按类型构建此函数
- Windows形成web浏览器控件和Javascript更改的DOM
- Datatables:通过DOM数据源中的名称引用列
- 在DOM中查找一个模式并替换它's的内容使用jquery
- DOM事件通过JSON转换为java
- 将DOM节点值与字符串Javascript进行比较
- delete在Object上效率低下,但在DOM Element's的数据属性,与null out相比
- 流星中DOM的繁殖
- DOM元素和angular元素之间的主要区别是什么
- 当带有渲染器的DOM元素不在屏幕顶部时,移动了场景的坐标
- 如何将Knockout.JS与服务器已经在DOM中呈现的数据同步
- PHP-如何重定向到同一页面并更改DOM's
- 如何使用ViewCompiler手动编译DOM的一部分
- 尝试创建事务时出现DOM IDBDatabase异常11
- NotFoundError:DOM IDBDatabase在indexedDB中创建事务时发生异常8
- InvalidStateError: DOM IDBDatabase Exception 11
- IndexedDB DOM IDBDatabase异常11即使使用oncomplete