aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/response/formdata/index.html
blob: 0c4c2a89fce89a255117abb1215210fff9a48a26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
title: Response.formData()
slug: Web/API/Response/formData
translation_of: Web/API/Response/formData
tags:
  - API
  - Fetch
  - Fetch API
  - FormData
  - Method
  - NeedsExample
  - Reference
  - Response
browser-compat: api.Response.formData
---
<div>{{APIRef("Fetch")}}</div>

<p> {{domxref("Response")}} 对象中的<strong><code>formData()</code></strong> 方法将 {{domxref("Response")}} 对象中的所承载的数据流读取并封装成为一个对象,该方法将返回一个 <strong><code>Promise</code></strong>  对象,该对象将产生一个{{domxref("FormData")}} 对象。</p>

<div class="note">
<p><strong>注意</strong>: 该方法主要与 <a href="/en-US/docs/Web/API/ServiceWorker_API">service workers</a> 有关. 如果客户端提交的一个表单请求被Service Worker 所截取,您可以像下述的样例一样,调用 <code>formData()</code> 方法来获取一个key-value 字典, 对该字典可以进行修饰, 然后将修饰后的表填提交给远端服务器 (或在本地应用)。</p>
</div>

<h2 id="语法">语法</h2>

<pre class="syntaxbox">response.formData()
.then(function(formdata) {
  // do something with your formdata
});</pre>

<h3 id="参数">参数</h3>

<p>无。</p>

<h3 id="返回值">返回值</h3>

<p>生成 {{domxref("FormData")}}对象的{{domxref("Promise")}} 对象.</p>

<h2 id="样例">样例</h2>

<p>待定.</p>

<h2 id="详述">详述</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Fetch','#dom-body-formdata','formData()')}}</td>
   <td>{{Spec2('Fetch')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

{{Compat("api.Response.formData")}}

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/ServiceWorker_API">ServiceWorker API</a></li>
 <li><a href="/en-US/docs/Web/HTTP/Access_control_CORS">HTTP access control (CORS)</a></li>
 <li><a href="/en-US/docs/Web/HTTP">HTTP</a></li>
</ul>