The XMLHttpRequest method send() sends the request to the server. If the request is asynchronous (which is the default), this method returns as soon as the request is sent and the result is delivered using events. If the request is synchronous, this method doesn't return until the response has arrived.

send() accepts an optional parameter which lets you specify the request's body; this is primarily used for requests such as PUT. If the request method is GET or HEAD, the body parameter is ignored and the request body is set to null.

If no Accept header has been set using the setRequestHeader(), an Accept header with the type "*/*" (any type) is sent.

Syntax

XMLHttpRequest.send(body)

Parameters

body Optional
A body of data to be sent in the XHR request. This can be: If no value is specified for the body, a default value of null is used.

The best way to send binary content (e.g. in file uploads) is by using an ArrayBufferView or Blob in conjunction with the send() method.

Return value

undefined.

Example: GET

var xhr = new XMLHttpRequest();
xhr.open('GET', '/server', true);

xhr.onload = function () {
  // Request finished. Do processing here.
};

xhr.send(null);
// xhr.send('string');
// xhr.send(new Blob());
// xhr.send(new Int8Array());
// xhr.send(document);

Example: POST

var xhr = new XMLHttpRequest();
xhr.open("POST", '/server', true);

//Send the proper header information along with the request
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

xhr.onreadystatechange = function() { // Call a function when the state changes.
    if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
        // Request finished. Do processing here.
    }
}
xhr.send("foo=bar&lorem=ipsum"); 
// xhr.send(new Blob()); 
// xhr.send(new Int8Array()); 
// xhr.send(document);

Specifications

Specification Status Comment
XMLHttpRequest
The definition of 'send()' in that specification.
Living Standard WHATWG living standard

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 7
Full support 7
Full support 5
Notes
Notes Implemented via ActiveXObject
Opera Full support YesSafari Full support 1.2WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
ArrayBuffer as parameter to send()Chrome Full support 9Edge Full support YesFirefox Full support 9IE Full support 10Opera Full support 11.6Safari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 9Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
ArrayBufferView as parameter to send()Chrome Full support 22Edge ? Firefox Full support 20IE ? Opera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 20Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
Blob as parameter to send()Chrome Full support 22Edge Full support YesFirefox Full support 2IE Full support 10Opera Full support 12Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 4Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
FormData as parameter to send()Chrome Full support 6Edge Full support YesFirefox Full support 2IE Full support 10Opera Full support 12Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 4Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
URLSearchParams as parameter to send()Chrome Full support 59Edge ? Firefox Full support 44IE ? Opera Full support 12Safari ? WebView Android Full support YesChrome Android Full support 59Edge Mobile ? Firefox Android Full support 44Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support 7.0

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

See also