Home

requestonsuccess

Request.onsuccess is a callback property of the IDBRequest interface used in the IndexedDB API to handle the successful completion of a database operation. It is commonly assigned to respond to operations such as add, put, delete, get, or cursor-related requests. When the operation completes without error, the onsuccess handler is invoked with an event object.

Within the onsuccess handler, the result of the operation can be accessed via event.target.result (or via request.result

The request.onsuccess handler can be defined in two common ways: by assigning a function directly to the

Compatibility and behavior: onsuccess is part of the standard IndexedDB API and is supported in major browsers.

in
some
contexts).
This
value
represents
the
data
retrieved
or
the
outcome
of
the
operation,
such
as
the
stored
object
for
a
get
request
or
the
key
for
an
add/put
operation.
The
handler
runs
after
the
underlying
transaction
has
progressed
to
a
successful
state,
and
it
is
typically
used
to
continue
application
logic
that
depends
on
the
retrieved
data
or
confirmation
of
the
operation.
onsuccess
property,
or
by
attaching
an
event
listener
for
the
'success'
event
via
addEventListener.
For
example,
a
get
request
might
set
request.onsuccess
=
function(event)
{
console.log(event.target.result);
};
or
use
request.addEventListener('success',
function(event)
{
...
});
The
latter
approach
offers
greater
flexibility
in
managing
multiple
listeners.
Errors
are
handled
separately
with
onerror,
and
the
transaction’s
overall
progress
is
governed
by
the
transaction's
lifecycle
and
error
handling
strategies.