表单数据() XHR2
我正在尝试使用 FormData()。我已经在 Chrome 和 Firefox 的多个版本中尝试过此代码。
var fData = new FormData();
fData.append('foo', 'bar');
console.log('formData', fData);
fData 在记录时只给我创建的对象,其原型为 FormData,没有附加的“foo”值。没有错误,它似乎只是默默地失败了。
我也尝试过
var fData = new FormData(formElement);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
做了一些研究,我发现这个问题说你不能直接从
FormData
对象获取数据。但是,如果您在发送数据后检查XMLHttpRequest
对象,则可以看到发送了哪些数据。这使我能够看到我发送的内容(我使用 Chrome 检查器的网络选项卡)并有效地调试我的代码。因此,回答您的问题:它可能已经开始工作,您只是看不到
FormData
对象中的数据。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 theXMLHttpRequest
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.