Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

XMLHttpRequest

BaselineWidely available *

Note: This feature is available inWeb Workers, except forService Workers.

XMLHttpRequest (XHR) objects are used to interact with servers. You can retrieve data from a URL without having to do a full page refresh. This enables a Web page to update just part of a page without disrupting what the user is doing.

EventTarget XMLHttpRequestEventTarget XMLHttpRequest

Despite its name,XMLHttpRequest can be used to retrieve any type of data, not just XML.

If your communication needs to involve receiving event data or message data from a server, consider usingserver-sent events through theEventSource interface. For full-duplex communication,WebSockets may be a better choice.

Constructor

XMLHttpRequest()

The constructor initializes anXMLHttpRequest. It must be called before any other method calls.

Instance properties

This interface also inherits properties ofXMLHttpRequestEventTarget and ofEventTarget.

XMLHttpRequest.readyStateRead only

Returns a number representing the state of the request.

XMLHttpRequest.responseRead only

Returns anArrayBuffer, aBlob, aDocument, a JavaScript object, or a string, depending on the value ofXMLHttpRequest.responseType, that contains the response entity body.

XMLHttpRequest.responseTextRead only

Returns a string that contains the response to the request as text, ornull if the request was unsuccessful or has not yet been sent.

XMLHttpRequest.responseType

Specifies the type of the response.

XMLHttpRequest.responseURLRead only

Returns the serialized URL of the response or the empty string if the URL is null.

XMLHttpRequest.responseXMLRead only

Returns aDocument containing the response to the request, ornull if the request was unsuccessful, has not yet been sent, or cannot be parsed as XML or HTML. Not available inWeb Workers.

XMLHttpRequest.statusRead only

Returns theHTTP response status code of the request.

XMLHttpRequest.statusTextRead only

Returns a string containing the response string returned by the HTTP server. UnlikeXMLHttpRequest.status, this includes the entire text of the response message ("OK", for example).

Note:According to the HTTP/2 specificationRFC 7540, section 8.1.2.4: Response Pseudo-Header Fields, HTTP/2 does not define a way to carry the version or reason phrase that is included in an HTTP/1.1 status line.

XMLHttpRequest.timeout

The time in milliseconds a request can take before automatically being terminated.

XMLHttpRequest.uploadRead only

AXMLHttpRequestUpload representing the upload process.

XMLHttpRequest.withCredentials

Returnstrue if cross-siteAccess-Control requests should be made using credentials such as cookies or authorization headers; otherwisefalse.

Non-standard properties

XMLHttpRequest.mozAnonRead onlyNon-standard

A boolean. If true, the request will be sent without cookie and authentication headers.

XMLHttpRequest.mozSystemRead onlyNon-standard

A boolean. If true, the same origin policy will not be enforced on the request.

Instance methods

XMLHttpRequest.abort()

Aborts the request if it has already been sent.

XMLHttpRequest.getAllResponseHeaders()

Returns all the response headers, separated byCRLF, as a string, ornull if no response has been received.

XMLHttpRequest.getResponseHeader()

Returns the string containing the text of the specified header, ornull if either the response has not yet been received or the header doesn't exist in the response.

XMLHttpRequest.open()

Initializes a request.

XMLHttpRequest.overrideMimeType()

Overrides the MIME type returned by the server.

XMLHttpRequest.send()

Sends the request. If the request is asynchronous (which is the default), this method returns as soon as the request is sent.

XMLHttpRequest.setAttributionReporting()Secure contextExperimental

Indicates that you want the request's response to be able to register an attribution source or trigger event.

XMLHttpRequest.setRequestHeader()

Sets the value of an HTTP request header. You must callsetRequestHeader() afteropen(), but beforesend().

Events

abort

Fired when a request has been aborted, for example because the program calledXMLHttpRequest.abort().Also available via theonabort event handler property.

error

Fired when the request encountered an error.Also available via theonerror event handler property.

load

Fired when anXMLHttpRequest transaction completes successfully.Also available via theonload event handler property.

loadend

Fired when a request has completed, whether successfully (afterload) or unsuccessfully (afterabort orerror).Also available via theonloadend event handler property.

loadstart

Fired when a request has started to load data.Also available via theonloadstart event handler property.

progress

Fired periodically when a request receives more data.Also available via theonprogress event handler property.

readystatechange

Fired whenever thereadyState property changes.Also available via theonreadystatechange event handler property.

timeout

Fired when progress is terminated due to preset time expiring.Also available via theontimeout event handler property.

Specifications

Specification
XMLHttpRequest
# interface-xmlhttprequest

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp