Home

responseText

ResponseText is a property of the XMLHttpRequest interface used in web browsers to expose the server’s response data as plain text. When a request completes successfully, responseText contains the response body interpreted as a string. It is commonly used for textual responses such as HTML, plain text, or XML, and is often contrasted with binary-oriented approaches or with higher-level APIs that automatically parse formats like JSON.

Access to responseText occurs after the load event, once the data has been received. If the response

In practice, responseText is frequently used to manually parse responses, for example to extract data from

Compatibility and evolution: responseText has been part of the traditional XMLHttpRequest API for many years and

See also: XMLHttpRequest, response, responseXML, responseType, Fetch API, JSON.parse.

body
is
not
textual
or
if
the
request
is
not
finished,
responseText
may
be
empty
or
undefined.
The
text
is
decoded
using
the
character
encoding
specified
by
the
server
in
the
Content-Type
header;
if
encoding
is
unclear
or
mismatched,
the
resulting
string
may
appear
garbled.
HTML
or
to
handle
non-JSON
payloads.
For
JSON
data,
developers
typically
call
JSON.parse
on
responseText
to
convert
it
to
an
object.
For
binary
data,
or
when
a
more
modern
approach
is
preferred,
other
XHR
properties
or
the
Fetch
API
are
used.
remains
widely
encountered
in
legacy
code.
Modern
web
development
often
favors
the
Fetch
API,
where
the
equivalent
operation
is
achieved
via
response.text(),
which
returns
a
promise
resolving
to
a
string.
This
shift
reflects
a
move
toward
promise-based,
streaming,
and
more
flexible
handling
of
responses.