Skip to content

Commit

Permalink
Merge branch 'XMLHttpRequestUpload' of github.com:teoli2003/content i…
Browse files Browse the repository at this point in the history
…nto XMLHttpRequestUpload
  • Loading branch information
teoli2003 committed Mar 30, 2023
2 parents 6a03622 + 32fb32d commit 9d6cfe0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion files/en-us/web/api/xmlhttprequestupload/index.md
Expand Up @@ -7,7 +7,7 @@ browser-compat: api.XMLHttpRequestUpload

{{DefaultAPISidebar("XMLHttpRequest")}}

The **`XMLHttpRequestUpload`** interface represents the upload process, allowing to listen for events associated with a specific {{domxref("XMLHttpRequest")}}. It is an _opaque_ object that represents the underlying, browser-dependant, upload process. It is {{domxref("XMLHttpRequestEventTarget")}} and is can be obtained by calling {{domxref("XMLHttpRequest.upload")}}.
The **`XMLHttpRequestUpload`** interface represents the upload process, allowing it to listen for events associated with a specific {{domxref("XMLHttpRequest")}}. It is an _opaque_ object that represents the underlying, browser-dependant, upload process. It is {{domxref("XMLHttpRequestEventTarget")}} and is can be obtained by calling {{domxref("XMLHttpRequest.upload")}}.

{{AvailableInWorkers("notservice")}}

Expand Down
@@ -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")}}

0 comments on commit 9d6cfe0

Please sign in to comment.