XMLHttpRequest: status property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Note: This feature is available in Web Workers, except for Service Workers.
The read-only XMLHttpRequest.status
property returns the numerical HTTP status code of the XMLHttpRequest
's response.
Before the request completes, the value of status
is 0. Browsers also report a status of 0 in case of XMLHttpRequest
errors.
Value
A number.
Examples
js
const xhr = new XMLHttpRequest();
console.log("UNSENT: ", xhr.status);
xhr.open("GET", "/server");
console.log("OPENED: ", xhr.status);
xhr.onprogress = () => {
console.log("LOADING: ", xhr.status);
};
xhr.onload = () => {
console.log("DONE: ", xhr.status);
};
xhr.send();
/**
* Outputs the following:
*
* UNSENT: 0
* OPENED: 0
* LOADING: 200
* DONE: 200
*/
Specifications
Specification |
---|
XMLHttpRequest Standard # the-status-attribute |
Browser compatibility
BCD tables only load in the browser
See also
- List of HTTP status
- HTTP