FormData
BaselineWidely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
Note: This feature is available inWeb Workers.
TheFormData
interface provides a way to construct a set of key/value pairs representing form fields and their values, which can be sent using thefetch()
,XMLHttpRequest.send()
ornavigator.sendBeacon()
methods. It uses the same format a form would use if the encoding type were set to"multipart/form-data"
.
You can also pass it directly to theURLSearchParams
constructor if you want to generate query parameters in the way a<form>
would do if it were using simpleGET
submission.
An object implementingFormData
can directly be used in afor...of
structure, instead ofentries()
:for (const p of myFormData)
is equivalent tofor (const p of myFormData.entries())
.
Constructor
FormData()
Creates a new
FormData
object.
Instance methods
FormData.append()
Appends a new value onto an existing key inside a
FormData
object, or adds the key if it does not already exist.FormData.delete()
Deletes a key/value pair from a
FormData
object.FormData.entries()
Returns aniterator that iterates through all key/value pairs contained in the
FormData
.FormData.get()
Returns the first value associated with a given key from within a
FormData
object.FormData.getAll()
Returns an array of all the values associated with a given key from within a
FormData
.FormData.has()
Returns whether a
FormData
object contains a certain key.FormData.keys()
Returns aniterator iterates through all keys of the key/value pairs contained in the
FormData
.FormData.set()
Sets a new value for an existing key inside a
FormData
object, or adds the key/value if it does not already exist.FormData.values()
Returns aniterator that iterates through all values contained in the
FormData
.
Specifications
Specification |
---|
XMLHttpRequest # interface-formdata |