如何检查FormData?我试过console.log并使用for in.在这里MDN参考在FormData上。两次尝试都在此进行。小提琴.var fd = new FormData(),
key;// poulate with dummy datafd.append("key1", "alskdjflasj");fd.append("key2", "alskdjflasj");
// does not do anything usefulconsole.log(fd);// does not do anything usefulfor(key in fd) {
console.log(key);}如何检查表单数据以查看设置了哪些键。
3 回答
慕妹3242003
TA贡献1824条经验 获得超6个赞
FormData.entries()
// Create a test FormData objectvar formData = new FormData();formData.append('key1', 'value1');formData.append('key2', 'value2'); // Display the key/value pairsfor (var pair of formData.entries()) { console.log(pair[0]+ ', ' + pair[1]); }
旧答案:
var myFormData = { key1: 300, key2: 'hello world'};var fd = new FormData();for (var key in myFormData) { console.log(key, myFormData[key]); fd.append(key, myFormData[key]);}
var xhr = new XMLHttpRequest;xhr.open('POST', '/', true);xhr.send(fd);
添加回答
举报
0/150
提交
取消