FormData
The FormData
interface provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using the XMLHttpRequest.send()
method. 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 (var p of myFormData)
is equivalent to for (var p of myFormData.entries())
.
Note: This feature is available in Web Workers.
Constructor
FormData()
-
Creates a new
FormData
object.
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
allowing to go through all key/value pairs contained in this object. 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 a boolean stating whether a
FormData
object contains a certain key. FormData.keys()
-
Returns an
iterator
allowing to go through all keys of the key/value pairs contained in this object. 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
allowing to go through all values contained in this object.
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 | |
FormData |
7 |
12 |
4
Before 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 |
≤37
XHR in Android 4.0 sends empty content for
FormData with blob . |
18 |
4
Before 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 |
FormData |
7 |
12 |
4 |
10 |
12 |
5 |
≤37 |
18 |
4 |
12 |
5 |
1.0 |
append |
7 |
12 |
4
Before 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
With 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 |
3
XHR in Android 4.0 sends empty content for
FormData with blob . |
18 |
4
Before 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 |
Yes |
11.1 |
50 |
50 |
Yes |
Yes |
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 |
Yes |
11.1 |
50 |
50 |
Yes |
Yes |
11.3 |
5.0 |
keys |
50 |
18 |
44 |
No |
Yes |
11.1 |
50 |
50 |
44 |
? |
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 |
@@iterator |
50 |
18 |
44 |
No |
37 |
11.1 |
50 |
50 |
44 |
37 |
11.3 |
5.0 |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/FormData