Response()

Baseline Widely available

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

Конструктор Response() создаёт новый объект Response.

Синтаксис

var myResponse = new Response(body, init);

Параметры

body Необязательный

Объект, который определяет тело запроса. Может быть null (является значением по умолчанию), или:

init Необязательный

An options object containing any custom settings that you want to apply to the response, or an empty object (which is the default value). The possible options are:

  • status: The status code for the reponse, e.g., 200.
  • statusText: The status message associated with the status code, e.g., OK.
  • headers: Any headers you want to add to your response, contained within a Headers (en-US) object or object literal of ByteString (en-US) key/value pairs (see HTTP headers for a reference).

Примеры

In our Fetch Response example (see Fetch Response live) we create a new Response object using the constructor, passing it a new Blob as a body, and an init object containing a custom status and statusText:

js
var myBlob = new Blob();
var init = { status: 200, statusText: "SuperSmashingGreat!" };
var myResponse = new Response(myBlob, init);

Спецификации

Specification
Fetch Standard
# ref-for-dom-response①

Совместимость с браузерами

BCD tables only load in the browser

Читай также