简体   繁体   English

FormData()XHR2

[英]FormData() XHR2

I am trying to use FormData(). 我正在尝试使用FormData()。 I have tried this code in Multiple versions of Chrome and Firefox. 我在多个版本的Chrome和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. 记录时,fData只给我创建的对象,其中包含FormData原型,没有额外的“foo”值。 There are no errors, it just seems to fail silently. 没有错误,它似乎无声地失败。

I have also tried 我也试过了

var fData = new FormData(formElement);

Doing a bit of research, I found this question which says you can't get your data directly from the FormData object. 做了一些研究,我发现这个问题说你无法直接从FormData对象获取数据。 However, you can see what data is sent if you examine the XMLHttpRequest object after sending it. 但是,如果在发送XMLHttpRequest对象后检查XMLHttpRequest对象,则可以查看发送的数据。 This allowed me to see what I was sending (I used the network tab of Chrome's inspector) and effectively debug my code. 这让我可以看到我发送的内容(我使用了Chrome检查器的网络标签)并有效地调试了我的代码。

So to answer your question: it is probably working already, you just can't see your data in the FormData object. 所以回答你的问题:它可能已经工作了,你只是无法在FormData对象中看到你的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM