I use two different events for the callback to respond when the IndexedDB transaction finishes or is successful:
Let’s say… db : IDBDatabase object, tr : IDBTransaction object, os : IDBObjectStore object
tr = db.transaction(os_name,'readwrite');
os = tr.objectStore();
case 1 :
r = os.openCursor();
r.onsuccess = function() {
if(r.result){
callback_for_result_fetched();
r.result.continue;
} else {
callback_for_transaction_finish();
}
}
case 2:
tr.oncomplete = callback_for_transaction_finish();
It is a waste if both of them work similarly. So can you tell me, is there any difference between them?
While it’s true these callbacks function similarly they are not the same: the difference between
onsuccessandoncompleteis that transactionscompletebut requests, which are made on those transactions, aresuccessful.oncompleteis only defined in the spec as related to a transaction. A transaction doesn’t have anonsuccesscallback.