W3cubDocs

/DOM

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

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

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

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 7 Yes 4
4
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.
10 12 5
FormData() constructor 7 Yes 4 10 12 5
append 7 Yes 4
4
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.
10
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
delete 50 No 39 No Yes 11
get 50 No 39 No Yes 11
getAll 50 No 39 No Yes 11
has 50 No 39 No Yes 11
set 50 No 39 No No 11
entries 50 No 44 No Yes 11
keys 50 No 44 ? Yes 11
values 50 No 44 ? ? 11
Support of for...of 50 No 44 ? ? 11
Available in workers Yes Yes 39 No Yes Yes
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes
Yes
XHR in Android 4.0 sends empty content for FormData with blob.
Yes Yes 4 12 ? ?
FormData() constructor Yes Yes Yes Yes 12 ? ?
append 3
3
XHR in Android 4.0 sends empty content for FormData with blob.
? Yes 4
4
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.
12 ? ?
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 No 44 Yes ? ?
keys ? 50 No 44 ? ? ?
values ? 50 No 44 ? ? ?
Support of for...of ? 50 No 44 ? ? ?
Available in workers Yes Yes Yes Yes Yes No ?

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/FormData