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.
Example
var xhr = new XMLHttpRequest();
console.log('UNSENT: ', xhr.status);
xhr.open('GET', '/server');
console.log('OPENED: ', xhr.status);
xhr.onprogress = function () {
console.log('LOADING: ', xhr.status);
};
xhr.onload = function () {
console.log('DONE: ', xhr.status);
};
xhr.send();
/**
* Outputs the following:
*
* UNSENT: 0
* OPENED: 0
* LOADING: 200
* DONE: 200
*/
Specifications
| Specification | Status | Comment |
|---|---|---|
| XMLHttpRequest | Living Standard | WHATWG living standard |
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
status | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE
Full support
7
| Opera Full support 8 | Safari Full support 1.2 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 |
Legend
- Full support
- Full support
- See implementation notes.
- See implementation notes.
See also
- List of HTTP response codes
- HTTP
