Indexeddb: Differences between onsuccess and oncomplete?

database, indexeddb, javascript

Solution

While it's true these callbacks function similarly they are not the same: the difference between `onsuccess` and `oncomplete` is that transactions `complete` but requests, which are made on those transactions, are `successful`.

`oncomplete` is only defined in the spec as related to a transaction. A transaction doesn't have an `onsuccess` callback.

Problem

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?

Original source