i get a problem to set the callback function before indexeddb add transaction
os = ...the object store (IDBObjectStore) object assigned here
os.onsuccess = function(){alert('dont mess with Messi')}
os.add({name:'Lionel Messi',team:'FC Barcelona',position:'striker',number:10});
the entry was successfully added to the object store, but the function on onsuccess event won’t fired. there’s another event called onerror. should i use it instead? i dont think so
don’t ask me for ‘can you give the error part?’ because there’s no error at all
You’re going about your request in the wrong way. There’s no error because you’re merely adding an
onsuccessattribute to an object that will never call it.You don’t add
onsuccesscallbacks to the object store, you open a transaction on theobjectStoreand add a listener to that transaction.For a working example using indexes and transactions, check out this jsfiddle I was recently working through with another StackOverflower.* For a more complex example, see my IndexedDB library.
*Note this fiddle is written to the old (pre-Dec 2011), Chrome IDB implementation. A newer (FF) implementation would use an
onupgradeneededcallback but would more or less otherwise be the same.