The readystatechange
event is fired whenever the readyState
property of the XMLHttpRequest
changes.
Warning: This should not be used with synchronous requests and must not be used from native code.
The readystatechange
event is fired whenever the readyState
property of the XMLHttpRequest
changes.
Warning: This should not be used with synchronous requests and must not be used from native code.
Use the event name in methods like addEventListener()
, or set an event handler property.
addEventListener('readystatechange', event => { }) onreadystatechange = event => { }
A generic Event
with no added properties.
const xhr = new XMLHttpRequest(), method = "GET", url = "https://developer.mozilla.org/"; xhr.open(method, url, true); xhr.onreadystatechange = function () { // In local files, status is 0 upon success in Mozilla Firefox if(xhr.readyState === XMLHttpRequest.DONE) { var status = xhr.status; if (status === 0 || (status >= 200 && status < 400)) { // The request has been completed successfully console.log(xhr.responseText); } else { // Oh no! There has been an error with the request! } } }; xhr.send();
Specification |
---|
XMLHttpRequest Standard # event-xhr-readystatechange |
XMLHttpRequest Standard # handler-xhr-onreadystatechange |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
readystatechange_event |
1
|
12
|
1
|
5
|
9
|
1.2
|
1
|
18
|
4
|
10.1
|
1
|
1.0
|
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readystatechange_event