FormData.append(" key" ;,"值")不起作用 [英] FormData.append("key", "value") is not working
问题描述
var formdata = new FormData();你可以告诉我这是什么错误:
formdata.append(key,value);
console.log(formdata);
我的输出看起来像这样,我找不到我的key - valuepair
FormData
* __ proto__:FormData
** append:function append(){[native code]}
***参数:null
***调用者:null
***长度:0
***名称:append
*** prototype:append $ b $ __ proto__:function Empty(){}
*构造函数:函数FormData(){[native code]}
**参数:null
**调用者:null
** length:0
** name:FormData
**原型:FormData
** toString:function toString(){[native code]}
* __ proto__:Object
** __ proto __:Object
** __ defineGetter __:function __defineGetter __(){[native code]}
** __ defineSetter __:function __defineSetter __(){[native code]}
** __ lookupGetter __:function __lookupGetter __(){[native code]}
** __ lookupSetter __:function __lookupSetter __(){[native code]}
** constructor:function Object(){[本地代码]}
** hasOwnProperty:func has hasOwnProperty(){[native code]}
** isPrototypeOf:function isPrototypeOf(){[native code]}
** propertyIsEnumerable:function propertyIsEnumerable(){[native code]}
** toLocaleString:function toLocaleString(){[native code]}
** toString:function toString(){[native code]}
** valueOf:function valueOf(){[native code]}
我无法理解!昨天它运行得非常好,今天我的脑袋碰撞了很多次! Firefox和Chrome浏览器,都是一样的:/ b / b> 解析方案
Chrome 50+和Firefox 39+ +):
$ b
formdata.entries()
Array.from()
用于调试)
formdata.get(key)
我通常会调试一个 FormData
对象,只是发送它(任何地方!浏览器日志(例如Chrome devtools的Network标签)。
你不需要一个/相同的Ajax框架。你不需要任何细节。发送它:
var xhr = new XMLHttpRequest;
xhr.open('POST','/',true);
xhr.send(data);
简单。
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() { [native code] }
***arguments: null
***caller: null
***length: 0
***name: "append"
***prototype: append
***__proto__: function Empty() {}
*constructor: function FormData() { [native code] }
**arguments: null
**caller: null
**length: 0
**name: "FormData"
**prototype: FormData
**toString: function toString() { [native code] }
*__proto__: Object
**__proto__: Object
**__defineGetter__: function __defineGetter__() { [native code] }
**__defineSetter__: function __defineSetter__() { [native code] }
**__lookupGetter__: function __lookupGetter__() { [native code] }
**__lookupSetter__: function __lookupSetter__() { [native code] }
**constructor: function Object() { [native code] }
**hasOwnProperty: function hasOwnProperty() { [native code] }
**isPrototypeOf: function isPrototypeOf() { [native code] }
**propertyIsEnumerable: function propertyIsEnumerable() { [native code] }
**toLocaleString: function toLocaleString() { [native code] }
**toString: function toString() { [native code] }
**valueOf: function valueOf() { [native code] }
I can't understand! Yesterday it worked so well, and today my head crashed the keyboard so many times! Firefox, Chrome, both the same :/
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:
var xhr = new XMLHttpRequest;
xhr.open('POST', '/', true);
xhr.send(data);
Easy.
这篇关于FormData.append(" key" ;,"值")不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!