Response()
Response()
构造函数创建了一个新的 Response
对象。
语法
let myResponse = new Response(body, init);
参数
- body 可选
-
一个定义 response 中 body 的对象。可以为
null
,或是以下其中一个: - init 可选
-
一个参数 (options) 对象,包含要应用到 response 上的任何自定义设置。可能参数 (options) 是:
status
: response 的状态码,例如:200
.statusText
: 和状态码关联的状态消息,例如:OK
.headers
: 你想加到 response 上的任何 headers,包含了一个Headers
对象或满足对象语法的ByteString
key/value 对 (详见 HTTP headers).
例子
在我们的 Fetch Response 示例中 (参见Fetch Response live) 我们使用构造函数创建了一个新的 Response 对象,传递一个新的 Blob
作为 body,和一个包含自定义 status
和statusText
的 init 对象:
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