Can you tell me whats wrong with this:
JavaScript
x
4
1
var formdata = new FormData();
2
formdata.append("key", "value");
3
console.log(formdata);
4
My output looks like this, I cant find my “key” – “value” pair
JavaScript
1
30
30
1
FormData
2
*__proto__: FormData
3
**append: function append() { [native code] }
4
***arguments: null
5
***caller: null
6
***length: 0
7
***name: "append"
8
***prototype: append
9
***__proto__: function Empty() {}
10
*constructor: function FormData() { [native code] }
11
**arguments: null
12
**caller: null
13
**length: 0
14
**name: "FormData"
15
**prototype: FormData
16
**toString: function toString() { [native code] }
17
*__proto__: Object
18
**__proto__: Object
19
**__defineGetter__: function __defineGetter__() { [native code] }
20
**__defineSetter__: function __defineSetter__() { [native code] }
21
**__lookupGetter__: function __lookupGetter__() { [native code] }
22
**__lookupSetter__: function __lookupSetter__() { [native code] }
23
**constructor: function Object() { [native code] }
24
**hasOwnProperty: function hasOwnProperty() { [native code] }
25
**isPrototypeOf: function isPrototypeOf() { [native code] }
26
**propertyIsEnumerable: function propertyIsEnumerable() { [native code] }
27
**toLocaleString: function toLocaleString() { [native code] }
28
**toString: function toString() { [native code] }
29
**valueOf: function valueOf() { [native code] }
30
I can’t understand! Yesterday it worked so well, and today my head crashed the keyboard so many times! Firefox, Chrome, both the same :/
Advertisement
Answer
New in Chrome 50+ and Firefox 39+ (resp. 44+):
formdata.entries()
(combine withArray.from()
for debugability)formdata.get(key)
- and more very useful methods
Original answer:
What I usually do to ‘debug’ a FormData
object, is just send it (anywhere!) and check the browser logs (eg. Chrome devtools’ Network tab).
You don’t need a/the same Ajax framework. You don’t need any details. Just send it:
JavaScript
1
4
1
var xhr = new XMLHttpRequest;
2
xhr.open('POST', '/', true);
3
xhr.send(data);
4
Easy.