Questions tagged [form-data]

FormData is a JavaScript object interface intended to build multipart/form-data in Ajax more easily.

FormData is a JavaScript object interface intended to build multipart/form-data in Ajax more easily and can be used to submit forms and file uploads to other web applications.

As it is defined in XMLHttpRequest Level 2 specification, the FormData object is an ordered collection of entries with a name, a value, a type, and optionally a filename (if type is "file").

FormData is supported in all modern browsers. Only IE9 and below will cause trouble but, if you’re supporting the older versions of IE, you’ll probably be using jQuery or another library which implements its own field data extraction method.

Some resources:

1864 questions
627
votes
13 answers

Sending multipart/formdata with jQuery.ajax

I've got a problem sending a file to a serverside PHP-script using jQuery's ajax-function. It's possible to get the File-List with $('#fileinput').attr('files') but how is it possible to send this Data to the server? The resulting array ($_POST) on…
zoku
  • 7,056
  • 3
  • 20
  • 27
376
votes
24 answers

How to inspect FormData?

I've tried console.log and looping through it using for in. Here it the MDN Reference on FormData. Both attempts are in this fiddle. var fd = new FormData(), key; // poulate with dummy data fd.append("key1", "alskdjflasj"); fd.append("key2",…
user1637281
260
votes
28 answers

Convert JS Object to form data

How can I can convert my JS Object to FormData? The reason why I want to do this is, I have an object that I constructed out of the ~100 form field values. var item = { description: 'Some Item', price : '0.00', srate : '0.00', color :…
Kamran Ahmed
  • 11,809
  • 23
  • 69
  • 101
237
votes
32 answers

How to convert FormData (HTML5 object) to JSON

How do I convert the entries from a HTML5 FormData object to JSON? The solution should not use jQuery. Also, it should not simply serialize the entire FormData object, but only its key/value entries.
Leonardo Villela
  • 2,498
  • 2
  • 12
  • 9
199
votes
15 answers

appending array to FormData and send via AJAX

I'm using ajax to submit a multipart form with array, text fields and files. I append each VAR to the main data as so var attachments = document.getElementById('files'); var data= new FormData(); for (i=0; i< attachments.files.length; i++){ …
shultz
  • 2,543
  • 3
  • 20
  • 23
121
votes
5 answers

Node.js: How to send headers with form data using request module?

I have code like the following: var req = require('request'); req.post('someUrl', { form: { username: 'user', password: '', opaque: 'someValue', logintype: '1'}, }, function (e, r, body) { console.log(body); }); How can I set headers…
Mike G.
  • 3,860
  • 3
  • 17
  • 18
118
votes
8 answers

FormData.append("key", "value") is not working

Can you tell me whats wrong with this: var formdata = new FormData(); formdata.append("key", "value"); console.log(formdata); My output looks like this, I cant find my "key" - "value" pair FormData *__proto__: FormData **append: function append() {…
netzaffin
  • 1,602
  • 3
  • 13
  • 14
116
votes
7 answers

fetch - Missing boundary in multipart/form-data POST

I want to send a new FormData() as the body of a POST request using the fetch api The operation looks something like this: var formData = new FormData() formData.append('myfile', file, 'someFileName.csv') fetch('https://api.myapp.com', { …
James
  • 4,927
  • 3
  • 22
  • 27
115
votes
4 answers

FormData created from an existing form seems empty when I log it

I'm trying to get a set of keys ( names or similar) and values ( values) from a web form: