XMLHttpRequest

Use XMLHttpRequest (XHR) objects 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.

MDN Reference

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion
Link copied to clipboard
sealed interface ReadyState

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Returns client's state.

Link copied to clipboard

Returns the response body.

Link copied to clipboard

Returns response as text.

Link copied to clipboard

Returns the response type.

Link copied to clipboard
Link copied to clipboard

Returns the response as document.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Can be set to a time in milliseconds. When set to a non-zero value will cause fetching to terminate after the given time has passed. When the time has passed, the request has not yet completed, and this's synchronous flag is unset, a timeout event will then be dispatched, or a "TimeoutError" DOMException will be thrown otherwise (for the send() method).

Link copied to clipboard
Link copied to clipboard

Returns the associated XMLHttpRequestUpload object. It can be used to gather transmission information when data is transferred to a server.

Link copied to clipboard

True when credentials are to be included in a cross-origin request. False when they are to be excluded in a cross-origin request and when cookies are to be ignored in its response. Initially false.

Functions

Link copied to clipboard
fun abort()

Cancels any network activity.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun open(method: RequestMethod, url: String)

Sets the request method, request URL, and synchronous flag.

fun open(method: RequestMethod, url: URL)
fun open(method: RequestMethod, url: String, async: Boolean, username: String? = definedExternally, password: String? = definedExternally)
fun open(method: RequestMethod, url: URL, async: Boolean, username: String? = definedExternally, password: String? = definedExternally)
Link copied to clipboard

Acts as if the Content-Type header value for a response is mime. (It does not change the header.)

Link copied to clipboard
fun send(body: BufferSource?)
fun send(body: String?)
fun send(body: Blob?)
fun send(body: FormData?)
fun send(body: URLSearchParams?)

fun send(body: Document? = definedExternally)

Initiates the request. The body argument provides the request body, if any, and is ignored if the request method is GET or HEAD.

Link copied to clipboard
fun setRequestHeader(name: String, value: String)

Combines a header in author request headers.