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".

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/value pair.
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 of the key/value pairs contained in this object.

Specifications

Specification Status Comment
XMLHttpRequest
The definition of 'FormData' in that specification.
Living Standard FormData defined in XHR spec

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support7 Yes4110125
FormData() constructor7 Yes410125
append7 Yes41103125
delete50 No39 No Yes Yes
get50 No39 No Yes Yes
getAll50 No39 No Yes Yes
has50 No39 No Yes Yes
set50 No39 No No Yes
entries50 No44 No Yes Yes
keys50 No44 ? Yes Yes
values50 No44 ? ? Yes
Support of for...of50 No44 ? ? Yes
Available in workers Yes Yes39 No Yes Yes
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes2 Yes Yes412 ? ?
FormData() constructor Yes Yes Yes Yes12 ? ?
append32 ? Yes4112 ? ?
delete ?50 No Yes Yes No ?
get ?50 No Yes Yes No ?
getAll ?50 No Yes Yes No ?
has ?50 No Yes Yes No ?
set ?50 No Yes No No ?
entries ?50 No44 Yes ? ?
keys ?50 No44 ? ? ?
values ?50 No44 ? ? ?
Support of for...of ?50 No44 ? ? ?
Available in workers Yes Yes Yes Yes Yes No ?

1. Prior to 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.

2. XHR in Android 4.0 sends empty content for FormData with blob.

3. 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).

See also