javascript - Failed to execute 'createObjectStore' on 'IDBDatabase' -
javascript - Failed to execute 'createObjectStore' on 'IDBDatabase' -
why have error ?
my code:
var idb = window.indexeddb || // utilize standard db api window.mozindexeddb || // or firefox's version of window.webkitindexeddb; // or chrome's version var idbtransaction = window.idbtransaction || window.webkitidbtransaction; var idbkeyrange = window.idbkeyrange || window.webkitidbkeyrange; var dbname='namedb'; var idbrequest=idb.open(dbname,'4.67' /*,dbdescription */); idbrequest.onsuccess=function (e) { debugger var db=e.target.result; if (!db.objectstorenames.contains('chat')){ co=db.createobjectstore('chat',{'id':100}); }; if (!db.objectstorenames.contains('iam')){ co1=db.createobjectstore('iam'); }; }; idbrequest.onerror = function (e) { debugger };
uncaught invalidstateerror: failed execute 'createobjectstore' on 'idbdatabase': database not running version alter transaction. index.html:37 idbrequest.onsuccess
you can't create objectstore in success command. can in upgradeneeded event.
quote docs:
when create new database or increment version number of existing database (by specifying higher version number did previously, when opening database), onupgradeneeded event triggered. in handler event, should create object stores needed version of database
see documentation.
javascript indexeddb
Comments
Post a Comment