可以't在IE10中创建IndexedDB数据库
Can't create IndexedDB database in IE10
我编写代码来创建数据库:
var db;
var request = indexedDB.open("TestDatabase");
request.onerror = function(evt) {
console.log("Database error code: " + evt.target.errorCode);
};
request.onsuccess = function(evt) {
db = request.result;
console.log(JSON.stringify(db));
};
它在FF/Chrome中运行良好,代码为:JSON.stringfy(db)返回JSON对象。但是,它在IE10中不起作用。代码:JSON.stringfy(db)返回一个空对象。
每个人都有同样的问题吗?你能花点时间帮我吗?谢谢
更新:我还检查了IE10中支持的IndexedDB,比如:
var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB;
结果是真的!我不知道JSON。stringify(db)总是返回一个空对象。:(
好吧,你的索引数据库是按实际定义的,这也是为什么你从得到了一个true
var indexedDB = window.indexedDB
这个问题是由JSON.stringfy()引起的,它在被要求序列化的任何对象上寻找toJSON()方法。变量db没有它,并且调用了db.toString()。
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
var db;
var request = window.indexedDB.open("TestDatabase",1);
request.onerror = function(evt) {
console.log("Database error code: " + evt.target.errorCode);
};
request.onsuccess = function(evt) {
db = request.result;
// extend the toJSON property for your indexeddb object
db.toJSON = function() {
return JSON.stringify({name : db.name});
};
//output: [object IDBDatabase]{constructor: IDBDatabase {...}, name: "TestDatabase", objectStoreNames: DOMStringList {...}, onabort: null, onerror: null, version: 1}
console.log(db);
// name is a inherit property
console.log(db.hasOwnProperty(name));
// name is not a numerable property
console.log(db.propertyIsEnumerable(name));
// toString returns a native object, not a JSON String, thats why you have {} with JSON.stringify(db)
console.log(db.toString);
// JSON.stringify call the db.toJSON(), and get the "{'"name'":'"TestDatabase'"}"
console.log(JSON.stringify(db));
};
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 为effect Composer创建GodRays效果过程
- 从javascript创建一个列表
- onkeyup无法动态创建多个文本区域
- 如何使用javascript从主svg对象动态创建svg视图框
- 如何访问声音管理器2创建的声音对象
- 我已经创建了一个jquery转盘,并使用if条件来运行和停止转盘
- Kendo:我该如何在树视图中创建一个递归的hieiarchy
- 使用Facebook live API创建实时视频对象时的隐私设置
- indexedDB创建数据库并添加内容执行失败'交易'在'IDBDatabase'
- IndexedDB - Dexie JS : 动态创建商店
- Safari 7.1 中使用 IndexedDB 创建多个对象存储时出现未知错误
- 是否可以在indexedDB上创建触发器
- IndexedDB正在创建带有空格的索引
- Safari:IndexedDB:无法在单独的事务中创建对象存储
- IndexedDB-无法创建多个对象存储并对其进行事务处理
- NotFoundError:DOM IDBDatabase在indexedDB中创建事务时发生异常8
- 在同一域的两个不同的离线web应用程序中创建/访问indexedDB使用相同的数据库
- 如何在IndexedDB中创建具有多个条件的查询
- 可以't在IE10中创建IndexedDB数据库