Home

readyState

readyState is a property used in web APIs to indicate the current loading status of a resource or document. In XMLHttpRequest, it represents the state of an asynchronous HTTP request with five possible values: 0 UNSENT, 1 OPENED, 2 HEADERS_RECEIVED, 3 LOADING, and 4 DONE. The value changes as the request progresses: 0 before open() is called, 1 after open(), 2 after a response header is received, 3 while the response body is downloading, and 4 when the operation completes. Developers often listen for the readystatechange event to react to state changes, and in the DONE state the response is available via xhr.response or xhr.responseText.

Separately, document.readyState reflects the loading state of the current document. It can be 'loading' while the

document
is
parsing,
'interactive'
once
the
document
has
been
parsed
but
subresources
may
still
be
loading,
and
'complete'
when
the
document
and
all
subresources
have
finished
loading.
Code
can
test
readyState
to
delay
actions
until
the
DOM
is
ready,
and
pages
commonly
rely
on
the
DOMContentLoaded
event
(fired
when
the
document
becomes
interactive)
or
the
load
event
(fired
when
all
resources
have
loaded).
Understanding
readyState
helps
manage
timing
for
scripts
and
data
handling
in
asynchronous
web
applications.