5

I am trying to use FormData(). I have tried this code in Multiple versions of Chrome and Firefox.

var fData = new FormData();
fData.append('foo', 'bar');
console.log('formData', fData);

fData, when logged, only gives me the created object with a prototype of FormData and no additional "foo" value. There are no errors, it just seems to fail silently.

I have also tried

var fData = new FormData(formElement);
Chris Biscardi
  • 3,148
  • 2
  • 20
  • 19

1 Answers1

7

Doing a bit of research, I found this question which says you can't get your data directly from the FormData object. However, you can see what data is sent if you examine the XMLHttpRequest object after sending it. This allowed me to see what I was sending (I used the network tab of Chrome's inspector) and effectively debug my code.

So to answer your question: it is probably working already, you just can't see your data in the FormData object.

Community
  • 1
  • 1
aganders3
  • 5,838
  • 26
  • 30
  • Awesome, thanks. It ended up that I wasn't receiving multipart/form-data on the server. Since I'm using node.js I had to use Formidable to receive the request. – Chris Biscardi Jan 13 '12 at 14:39
  • How do you see the request data in the XMLHttpRequest object? It seems like there isn't a property for security reasons. – Mark Chackerian Dec 01 '15 at 22:15