The formData()
method of the Request
interface reads the request body and returns it as a promise that resolves with a FormData
object.
The formData()
method of the Request
interface reads the request body and returns it as a promise that resolves with a FormData
object.
js
formData()
None.
js
const formData = new FormData(); const fileField = document.querySelector('input[type="file"]'); formData.append("username", "abc123"); formData.append("avatar", fileField.files[0]); const request = new Request("/myEndpoint", { method: "POST", body: formData, }); request.formData().then((data) => { // do something with the formdata sent in the request });
Specification |
---|
Fetch Standard # ref-for-dom-body-formdata① |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
formData |
60 | 79 | 39 | No | 47 | 14.1 | 60 | 60 | 39 | 44 | 14.5 | 8.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Request/formData