Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'XMLHttpRequestUpload' of github.com:teoli2003/content i…
…nto XMLHttpRequestUpload
- Loading branch information
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
files/en-us/web/api/xmlhttprequestupload/readystatechange_event/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
title: 'XMLHttpRequestUpload: readystatechange event' | ||
slug: Web/API/XMLHttpRequestUpload/readystatechange_event | ||
page-type: web-api-event | ||
browser-compat: api.XMLHttpRequestUpload.readystatechange_event | ||
--- | ||
|
||
{{APIRef}} | ||
|
||
The `readystatechange` event is fired whenever the {{domxref("XMLHttpRequest.readyState", "readyState")}} property of the {{domxref("XMLHttpRequest")}} changes. | ||
|
||
> **Warning:** This should not be used with synchronous requests and must | ||
> not be used from native code. | ||
## Syntax | ||
|
||
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property. | ||
|
||
```js | ||
addEventListener('readystatechange', (event) => { }) | ||
|
||
onreadystatechange = (event) => { } | ||
``` | ||
|
||
## Event type | ||
|
||
A generic {{DOMxRef("Event")}} with no added properties. | ||
|
||
## Examples | ||
|
||
```js | ||
const xhr = new XMLHttpRequest(); | ||
const method = "GET"; | ||
const url = "https://developer.mozilla.org/"; | ||
|
||
xhr.open(method, url, true); | ||
xhr.onreadystatechange = () => { | ||
// In local files, status is 0 upon success in Mozilla Firefox | ||
if (xhr.readyState === XMLHttpRequest.DONE) { | ||
const 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(); | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{domxref("XMLHttpRequestUpload")}} |