Skip to content

Latest commit

 

History

History
82 lines (69 loc) · 3.03 KB

File metadata and controls

82 lines (69 loc) · 3.03 KB
title slug page-type browser-compat
XMLHttpRequest.upload
Web/API/XMLHttpRequest/upload
web-api-instance-property
api.XMLHttpRequest.upload

{{APIRef('XMLHttpRequest')}}

The {{domxref("XMLHttpRequest")}} upload property returns an {{domxref("XMLHttpRequestUpload")}} object that can be observed to monitor an upload's progress.

It is an opaque object, but because it's also an {{domxref("XMLHttpRequestEventTarget")}}, event listeners can be attached to track its process.

Note: Attaching event listeners to this object prevents the request from being a "simple request" and will cause a preflight request to be issued if cross-origin; see CORS. Because of this, event listeners need to be registered before calling {{domxref("XMLHttpRequest.send", "send()")}} or upload events won't be dispatched.

Note: The spec also seems to indicate that event listeners should be attached after {{domxref("XMLHttpRequest.open", "open()")}}. However, browsers are buggy on this matter, and often need the listeners to be registered before {{domxref("XMLHttpRequest.open", "open()")}} to work.

The following events can be triggered on an upload object and used to monitor the upload:

Event Description
{{domxref("XMLHttpRequestUpload/loadstart_event", "loadstart")}} The upload has begun.
{{domxref("XMLHttpRequestUpload/progress_event", "progress")}} Periodically delivered to indicate the amount of progress made so far.
{{domxref("XMLHttpRequestUpload/abort_event", "abort")}} The upload operation was aborted.
{{domxref("XMLHttpRequestUpload/error_event", "error")}} The upload failed due to an error.
{{domxref("XMLHttpRequestUpload/load_event", "load")}} The upload completed successfully.
{{domxref("XMLHttpRequestUpload/timeout_event", "timeout")}} The upload timed out because a reply did not arrive within the time interval specified by the {{domxref("XMLHttpRequest.timeout")}}.
{{domxref("XMLHttpRequestUpload/loadend_event", "loadend")}} The upload finished. This event does not differentiate between success or failure, and is sent at the end of the upload regardless of the outcome. Prior to this event, one of load, error, abort, or timeout will already have been delivered to indicate why the upload ended.

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also