从HTML5 FormData对象获取所有项目 - HTML5 [英] Get All Items from HTML5 FormData Object - HTML5

查看:684
本文介绍了从HTML5 FormData对象获取所有项目 - HTML5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用HTML5 FormData对象,我似乎无法弄清楚如何找到它所拥有的数据。我需要访问它以进行调试。



的文档。



在Chrome中,您可以通过在浏览器标记部分下启用启用实验性网络平台功能来启用对这些功能的完全访问权限。在浏览器中导航到 chrome:// flags / 以查找此选项。



启用此功能并重新加载后,您应该可以运行以下命令查看所有 FormData ,data:

  var formData = new FormData(this); 
var formKeys = formData.keys();
var formEntries = formData.entries();

do {
console.log(formEntries.next()。value);
} while(!formKeys.next()。done)

当然,有可能迭代这个数据结构的更好方法,虽然它肯定是一种动态查看 FormData 对象中所有K / V对的方法。


I have been working with the HTML5 FormData object and I can't seem to figure out how to find what data it holds. I need to access it for debugging purposes.

https://developer.mozilla.org/en-US/docs/Web/API/FormData1

There are functions like

FormData::get([name]);

but I don't know the names. It would be nice to have something like the following:

FormData::dumpData();

What is a good way to view all of the data in a FormData object?

Update

Here is an example of the FormData object:

解决方案

All the functions for FormData aren't available in all browsers by default. However, you can enable them in some. Checkout the docs for browser compatibility.

In Chrome, you'll be able to enable full access to these functions by enabling Enable experimental Web Platform feature under the browser flags section. Navigate to chrome://flags/ in the browser to find this option.

Once you've enable this feature and reloaded, you should be able to run the following to view all your FormData, data:

var formData    = new FormData(this);
var formKeys    = formData.keys();
var formEntries = formData.entries();

do {
  console.log(formEntries.next().value);
} while (!formKeys.next().done)

Granted, there are probably better ways to iterate over this data structure, although it is certainly one way to view all the K/V pairs in your FormData object dynamically.

这篇关于从HTML5 FormData对象获取所有项目 - HTML5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆