XMLHttpRequest: XMLHttpRequest() constructor

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Note: This feature is available in Web Workers, except for Service Workers.

The XMLHttpRequest() constructor creates a new XMLHttpRequest.

Syntax

js
new XMLHttpRequest()

Parameters

None.

Return value

A new XMLHttpRequest object. The object must be prepared by at least calling open() to initialize it before calling send() to send the request to the server.

Non-standard Firefox syntax

Firefox 16 added a non-standard parameter to the constructor that can enable anonymous mode (see Firefox bug 692677). Setting the mozAnon flag to true effectively resembles the AnonXMLHttpRequest() constructor described in older versions of the XMLHttpRequest specification.

js
const request = new XMLHttpRequest(paramsDictionary);

Parameters (non-standard)

objParameters

One flag you can set:

mozAnon

Boolean: Setting this flag to true will cause the browser not to expose the origin and user credentials when fetching resources. Most important, this means that cookies will not be sent unless explicitly added using setRequestHeader.

Specifications

Specification
XMLHttpRequest Standard
# dom-xmlhttprequest

Browser compatibility

BCD tables only load in the browser

See also