[英]FormData object returns empty even for a non-empty form
FormData
object is empty for a form with 2 input fields. 对于具有2个输入字段的表单, FormData
对象为空。 formData.getAll()
logs a error TypeError: Not enough arguments to FormData.getAll.
formData.getAll()
记录错误TypeError: Not enough arguments to FormData.getAll.
. 。 Here is my code: 这是我的代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
function test () {
var element = document.getElementById("invite-form");
console.log(element);
var formdata = new FormData(element)
console.log(formdata.getAll());
}
</script>
</head>
<body>
<form id="invite-form" method='POST' action=''>
<label for="email">Email...</label>
<input type="text" name="email" value="human@earth.com"/>
<input type="hidden" name="csrf_token" value="random" />
<button class="btn" onclick="test()">Button</button>
</form>
</body>
</html>
I tried to populate the FormData
object with the values from the form on clicking the button 我尝试在单击按钮时使用表单中的值填充FormData
对象
The getAll()
method of the FormData interface requires a key to be given. FormData接口的getAll()
方法需要提供一个密钥。
It then returns all the values associated with that key from within a FormData object. 然后,它从FormData对象中返回与该键关联的所有值。
function test () {
var element = document.getElementById("invite-form");
console.log(element);
var formdata = new FormData(element)
console.log(formdata.getAll('email')); // <- needs key
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.