A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/en-US/docs/Web/API/XMLHttpRequest/send below:

XMLHttpRequest: send() method - Web APIs

XMLHttpRequest: send() method

Baseline Widely available

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

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 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 a TypedArray, a DataView or a Blob object in conjunction with the send() method.

Return value

None (undefined).

Exceptions
InvalidStateError DOMException

Thrown if send() has already been invoked for the request, and/or the request is complete.

NetworkError DOMException

Thrown if the resource type to be fetched is a Blob, and the method is not GET.

Example: GET
const xhr = new XMLHttpRequest();
xhr.open("GET", "/server", true);

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

xhr.send(null);
// xhr.send('string');
// xhr.send(new Blob());
// xhr.send(new Int8Array());
// xhr.send(document);
Example: POST
const 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 = () => {
  // Call a function when the state changes.
  if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
    // Request finished. Do processing here.
  }
};
xhr.send("foo=bar&lorem=ipsum");
// xhr.send(new Int8Array());
// xhr.send(document);
Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4