The FormData
interface provides a way to construct a set of key/value pairs representing form fields and their values, which can be sent using the fetch()
, XMLHttpRequest.send()
or navigator.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 the URLSearchParams
constructor if you want to generate query parameters in the way a <form>
would do if it were using simple GET
submission.
An object implementing FormData
can directly be used in a for...of
structure, instead of entries()
: for (const p of myFormData)
is equivalent to for (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 an iterator 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 an iterator 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 an iterator that iterates through all values contained in the FormData
.
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
@@iterator |
50 |
18 |
44 |
No |
37 |
11.1 |
50 |
50 |
44 |
37 |
11.3 |
5.0 |
FormData |
5 |
12 |
4 |
10 |
12 |
5 |
3 |
18 |
4 |
12 |
5 |
1.0 |
FormData |
5 |
12 |
4Before Firefox 7, specifying a Blob as the data to append to the object, the filename reported in the Content-Disposition HTTP header was an empty string, resulting in errors on some servers. Starting with Firefox 7, the filename blob is sent.
|
10 |
12 |
5 |
3XHR in Android 4.0 sends empty content for FormData with blob .
|
18 |
4Before Firefox 7, specifying a Blob as the data to append to the object, the filename reported in the Content-Disposition HTTP header was an empty string, resulting in errors on some servers. Starting with Firefox 7, the filename blob is sent.
|
12 |
5 |
1.0 |
append |
5 |
12 |
4Before Firefox 7, specifying a Blob as the data to append to the object, the filename reported in the Content-Disposition HTTP header was an empty string, resulting in errors on some servers. Starting with Firefox 7, the filename blob is sent.
|
10With the "Include local directory pass when uploading files to a server" option enabled, IE will change the filename inside the Blob on the fly. To have direct control of the sent filename, the developer should send the filename as the third parameter value, i.e. formData.append(name, value, filename) .
|
12 |
5 |
3XHR in Android 4.0 sends empty content for FormData with blob .
|
18 |
4Before Firefox 7, specifying a Blob as the data to append to the object, the filename reported in the Content-Disposition HTTP header was an empty string, resulting in errors on some servers. Starting with Firefox 7, the filename blob is sent.
|
12 |
5 |
1.0 |
delete |
50 |
18 |
39 |
No |
37 |
11.1 |
50 |
50 |
39 |
37 |
11.3 |
5.0 |
entries |
50 |
18 |
44 |
No |
37 |
11.1 |
50 |
50 |
44 |
37 |
11.3 |
5.0 |
forEach |
50 |
18 |
47 |
No |
37 |
11.1 |
50 |
50 |
47 |
37 |
11.3 |
5.0 |
get |
50 |
18 |
39 |
No |
37 |
11.1 |
50 |
50 |
39 |
37 |
11.3 |
5.0 |
getAll |
50 |
18 |
39 |
No |
37 |
11.1 |
50 |
50 |
39 |
37 |
11.3 |
5.0 |
has |
50 |
18 |
39 |
No |
37 |
11.1 |
50 |
50 |
39 |
37 |
11.3 |
5.0 |
keys |
50 |
18 |
44 |
No |
37 |
11.1 |
50 |
50 |
44 |
37 |
11.3 |
5.0 |
set |
50 |
18 |
39 |
No |
37 |
11.1 |
50 |
50 |
39 |
37 |
11.3 |
5.0 |
values |
50 |
18 |
44 |
No |
37 |
11.1 |
50 |
50 |
44 |
37 |
11.3 |
5.0 |
worker_support |
50 |
79 |
39 |
No |
37 |
13.1 |
50 |
50 |
39 |
37 |
13.4 |
5.0 |
See also