Response: formData() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
Note: This feature is available inWeb Workers.
TheformData() method of theResponse interfacetakes aResponse stream and reads it to completion. It returns a promisethat resolves with aFormData object.
Note:This is mainly relevant toservice workers. If a user submitsa form and a service worker intercepts the request, you could for example callformData() on it to obtain a key-value map, modify some fields, then sendthe form onwards to the server (or use it locally).
In this article
Syntax
js
formData()Parameters
None.
Return value
Exceptions
AbortErrorDOMExceptionThe request wasaborted.
TypeErrorThrown for one of the following reasons:
- The response body isdisturbed or locked.
- There was an error decoding the body content (for example, because the
Content-Encodingheader is incorrect). - TheMIME type of the body cannot be determined from the
Content-Typeheaders included in the response, or is notapplication/x-www-form-urlencodedormultipart/form-data. - The body cannot be parsed as a
FormDataobject.
Examples
TBD.
Specifications
| Specification |
|---|
| Fetch> # ref-for-dom-body-formdata①> |