I've tried console.log
and looping it using for in
.
Here is the MDN reference for FormData.
Both attempts are in this fiddle.
var fd = new FormData(), key; // poulate with dummy data fd.append("key1", "alskdjflasj"); fd.append("key2", "alskdjflasj"); // does not do anything useful console.log(fd); // does not do anything useful for(key in fd) { console.log(key); }
How to check the form data to see which keys have been set.
Some short answers
Longer answer
Others have suggested logging each
entry
of fd.entries(), butconsole.log
can also take multiple argumentsconsole.log(foo , bar, ...)
To accept any number of arguments, you can use the
apply
method and call it as follows:console.log.apply(console,array )
.But there is a new ES6 way to do this using spread operator a> and iterator
console.log(...array)
.Know this, and the fact that both FormData and arrays have a Symbol.iterator method specifies the default for in its prototype. ..of loop, then you can use
...iterable
to expand the parameters without having to call theformData.entries()
method (because this is the default function) if you If you like, you can executefor (x of formData)
If you want to check what the original body looks like, then you can use the response constructor (part of the Get API), which will convert your form data to what it actually looks like when you upload the form data
Update method:
As of March 2016, the latest versions of Chrome and Firefox now support checking FormData using
FormData.entries()
. source.Thanks to Ghost Echo and rloth for pointing this out!
Old answer:
Looking at these Mozilla articles, it looks like there is no way to get the data from the FormData object. You can only use them to build FormData to send via AJAX requests.
I also just found this question saying the same thing: FormData.append("key", "value") doesn't work .
One way to solve this problem is to build a regular dictionary and then convert it to FormData:
If you want to debug a plain FormData object, you can also send it to inspect it in the Network Requests console: