Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

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.

interface XMLHttpRequest extends XMLHttpRequestEventTarget {
readonly DONE: number;
readonly HEADERS_RECEIVED: number;
readonly LOADING: number;
onreadystatechange: ((this: XMLHttpRequest, ev: Event) => any) | null;
readonly OPENED: number;
readonly readyState: number;
readonly response: any;
readonly responseText: string;
readonly responseURL: string;
readonly responseXML: Document | null;
readonly status: number;
readonly statusText: string;
timeout: number;
readonly UNSENT: number;
readonly upload: XMLHttpRequestUpload;
withCredentials: boolean;
abort(): void;
addEventListener<K extends keyof XMLHttpRequestEventMap>(
type: K,
listener: (this: XMLHttpRequest, ev: XMLHttpRequestEventMap[K]) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
options?: boolean | AddEventListenerOptions,
): void;
getAllResponseHeaders(): string;
getResponseHeader(name: string): string | null;
open(method: string, url: string | URL): void;
open(
method: string,
url: string | URL,
async: boolean,
username?: string | null,
password?: string | null,
): void;
overrideMimeType(mime: string): void;
removeEventListener<K extends keyof XMLHttpRequestEventMap>(
type: K,
listener: (this: XMLHttpRequest, ev: XMLHttpRequestEventMap[K]) => any,
options?: boolean | EventListenerOptions,
): void;
removeEventListener(
type: string,
options?: boolean | EventListenerOptions,
): void;
send(body?: Document | XMLHttpRequestBodyInit | null): void;
setRequestHeader(name: string, value: string): void;
}
var XMLHttpRequest: {
prototype: XMLHttpRequest;
readonly DONE: number;
readonly HEADERS_RECEIVED: number;
readonly LOADING: number;
readonly OPENED: number;
readonly UNSENT: number;
new (): XMLHttpRequest;
}
;

§Extends

§Properties

§
readonly DONE: number
[src]
§
readonly HEADERS_RECEIVED: number
[src]
§
readonly LOADING: number
[src]
§
onreadystatechange: ((this: XMLHttpRequest, ev: Event) => any) | null
[src]
§
readonly OPENED: number
[src]
§
readonly readyState: number
[src]

Returns client's state.

§
readonly response: any
[src]

Returns the response body.

§
readonly responseText: string
[src]

Returns response as text.

Throws an "InvalidStateError" DOMException if responseType is not the empty string or "text".

§

Returns the response type.

Can be set to change the response type. Values are: the empty string (default), "arraybuffer", "blob", "document", "json", and "text".

When set: setting to "document" is ignored if current global object is not a Window object.

When set: throws an "InvalidStateError" DOMException if state is loading or done.

When set: throws an "InvalidAccessError" DOMException if the synchronous flag is set and current global object is a Window object.

§
readonly responseURL: string
[src]
§
readonly responseXML: Document | null
[src]

Returns the response as document.

Throws an "InvalidStateError" DOMException if responseType is not the empty string or "document".

§
readonly status: number
[src]
§
readonly statusText: string
[src]
§
timeout: number
[src]

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).

When set: throws an "InvalidAccessError" DOMException if the synchronous flag is set and current global object is a Window object.

§
readonly UNSENT: number
[src]
§
readonly upload: XMLHttpRequestUpload
[src]

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

§
withCredentials: boolean
[src]

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.

When set: throws an "InvalidStateError" DOMException if state is not unsent or opened, or if the send() flag is set.

§Methods

§
abort(): void
[src]

Cancels any network activity.

§
addEventListener<K extends keyof XMLHttpRequestEventMap>(
type: K,
listener: (this: XMLHttpRequest, ev: XMLHttpRequestEventMap[K]) => any,
options?: boolean | AddEventListenerOptions,
): void
[src]
§
addEventListener(
type: string,
options?: boolean | AddEventListenerOptions,
): void
[src]
§
getAllResponseHeaders(): string
[src]
§
getResponseHeader(name: string): string | null
[src]
§
open(method: string, url: string | URL): void
[src]

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

Throws a "SyntaxError" DOMException if either method is not a valid method or url cannot be parsed.

Throws a "SecurityError" DOMException if method is a case-insensitive match for CONNECT, TRACE, or TRACK.

Throws an "InvalidAccessError" DOMException if async is false, current global object is a Window object, and the timeout attribute is not zero or the responseType attribute is not the empty string.

§
open(
method: string,
url: string | URL,
async: boolean,
username?: string | null,
password?: string | null,
): void
[src]
§
overrideMimeType(mime: string): void
[src]

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

Throws an "InvalidStateError" DOMException if state is loading or done.

§
removeEventListener<K extends keyof XMLHttpRequestEventMap>(
type: K,
listener: (this: XMLHttpRequest, ev: XMLHttpRequestEventMap[K]) => any,
options?: boolean | EventListenerOptions,
): void
[src]
§
removeEventListener(
type: string,
options?: boolean | EventListenerOptions,
): void
[src]
§
send(body?: Document | XMLHttpRequestBodyInit | null): void
[src]

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

Throws an "InvalidStateError" DOMException if either state is not opened or the send() flag is set.

§
setRequestHeader(name: string, value: string): void
[src]

Combines a header in author request headers.

Throws an "InvalidStateError" DOMException if either state is not opened or the send() flag is set.

Throws a "SyntaxError" DOMException if name is not a header name or if value is not a header value.