我已经尝试了console.log和循环通过它使用for in。
这里是关于FormData的MDN参考。
两种尝试都在这把小提琴上。
var fd = new FormData(),
key;
// poulate with dummy data
fd.append("key1", "alskdjflasj");
fd.append("key2", "alskdjflasj");
// does not do anything useful
console.log(fd);
// does not do anything useful
for(key in fd) {
console.log(key);
}
如何检查表单数据以查看已设置的键。
基于@2540625回答一个ECMAScript 5兼容版本…
// NOTE: Inspect a HTML request data ("FormData"). By Questor
function inspRqstData(rqstData) {
var dataEntries = rqstData.entries();
var rqstDataAsJO = {};
var dataNext;
var dataPair;
while ((dataNext = dataEntries.next() || true) && dataNext.done === false) {
dataPair = dataNext.value;
console.log(dataPair[0], dataPair[1]);
}
}
var rqstData = new FormData();
rqstData.append('key1', 'value1');
rqstData.append('key2', 'value2');
inspRqstData(rqstData);
注意:“FormData”可以是框架“ECMAScript 5”JavaScript支持的东西。这可以通过这些参考文献中关于浏览器支持/兼容性的交叉信息推断出来(见IE10)…
https://www.w3schools.com/js/js_es5.asp
https://developer.mozilla.org/en-US/docs/Web/API/FormData/FormData#browser_compatibility
额外:转换一个HTML请求数据(“FormData”)到一个简单的JavaScript对象…
// NOTE: Convert a HTML request data ("FormData") to a JavaScript Object. By Questor
function rqstDataToJO(rqstData) {
var dataEntries = rqstData.entries();
var rqstDataAsJO = {};
var dataNext;
var dataPair;
while ((dataNext = dataEntries.next() || true) && dataNext.done === false) {
dataPair = dataNext.value;
rqstDataAsJO[dataPair[0]] = dataPair[1];
}
return rqstDataAsJO;
}
var rqstData = new FormData();
rqstData.append("key1", "value1");
rqstData.append("key2", "value2");
var rqstDataAsJO = rqstDataToJO(rqstData);
console.log(rqstDataAsJO.key1)
console.log(rqstDataAsJO.key1)
谢谢!= D
其他引用…
https://developer.mozilla.org/en-US/docs/Web/API/FormData/entries
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of