Response() - Web APIs 编辑

The Response() constructor creates a new Response object.

Syntax

var myResponse = new Response(body, init);

Parameters

body Optional
An object defining a body for the response. This can be null (which is the default value), or one of:
init Optional
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 object or object literal of ByteString key/value pairs (see HTTP headers for a reference).

Examples

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:

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

Specifications

SpecificationStatusComment
Fetch
The definition of 'Response()' in that specification.
Living StandardInitial definition

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:91 次

字数:3758

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文