“无法调用未定义的方法'open'"使用indexedDB.open时发生错误 [英] "Cannot call method 'open' of undefined" error when using indexedDB.open

查看:44
本文介绍了“无法调用未定义的方法'open'"使用indexedDB.open时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是IndexedDB的新手,并且正在遵循本指南 IndexedDB教程我只是尝试创建一个数据库,然后能够添加一些条目.到目前为止,这就是我所拥有的.

I am new to IndexedDB and I am following this guide IndexedDB Tutorial I am simply trying to create a database and then be able to add a few entries. This is what I have so far.

var db = window.indexedDB.open('FriendDB', 'My Friends!');

if (db.version != '1') {
    // User's first visit, initialize database (name, key, auto increment).
    db.createObjectStore('Friends', 'id', true);
    db.setVersion('1');
} else {
  // DB already initialized.
}

var store = db.openObjectStore('Friends');
var user = store.put({name: 'Eric', gender: 'male', likes: 'html5'});

在我的控制台中,我收到错误消息无法调用未定义的方法'open'",如何使它正常工作?另外,如果有更好的在线资源对我有帮助,因为对于新手,我似乎在IndexedDB主题上找不到任何东西.

In my console I get the error "Cannot call method 'open' of undefined" how can I get this working? Also if there is a better resource online that would help me because I can't seem to find anything on the topic of IndexedDB for a newbie.

推荐答案

这是html5rocks的indexeddb演示,我对其进行了改进以在Mozilla Firefox上工作,并添加了用于查看详细信息数据和编辑现有数据的功能.里面有解释如何在indexeddb中创建数据库,插入,更新和删除数据的说明.

Here is the indexeddb demo from html5rocks which i have improved to work on Mozilla Firefox and added features for viewing details data and editing existing data. Inside you have explanations how to create db, insert, update and delete data in indexeddb.

https://github.com/denimf/IndexedDbToDo

这篇关于“无法调用未定义的方法'open'"使用indexedDB.open时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆