我正在尝试通过ajax提交包含数据的表单,但是我的表单数据数组始终为空。你能帮我吗。我尝试了序列化和FormData这两种方法,但是都以一个空数组作为响应。
jQuery代码:
$("#inschrijvencursus").submit(function(e) {
e.preventDefault();
var fd = $("#inschrijvencursus").serialize();
// var fd = new FormData(this);
$.ajax({
url: "/wp-content/themes/tweb/page-cursistenopgeven.php",
data: fd,
// cache: false,
// processData: false,
// contentType: false,
type: 'POST',
success: function (data) {
console.log(data);
$('#formdata').html(data);
}
});
表格:
<form method="post" id="inschrijvencursus">
<div class="form-group">
<label for="company-name">Bedrijfsnaam</label>
<input type="text" class="form-control" id="company" placeholder="Bedrijfsnaam">
</div>
<div class="form-group">
<label for="name">Naam</label>
<input type="text" class="form-control" id="name" placeholder="Naam">
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="inlineCheckbox1" value="option1">
<label class="form-check-label" for="inlineCheckbox1">Man</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="inlineCheckbox2" value="option2">
<label class="form-check-label" for="inlineCheckbox2">Vrouw</label>
</div>
<div class="form-group">
<label for="name">Telefoonnummer</label>
<input type="tel" class="form-control" id="telephone" placeholder="Telefoonnummer">
</div>
<div class="form-group">
<label for="name">Email</label>
<input type="email" class="form-control" id="email" placeholder="Email">
</div>
<div class="form-group">
<label for="exampleTextarea">Opmerkingen</label>
<textarea class="form-control" id="opmerkingen" rows="3"></textarea>
</div>
<input type="submit" id="cursussubmit" class="nexttab"></button>
</form>
答案 0 :(得分:0)
找到解决方案。使用序列化功能时,表单中的输入元素需要一个name =“ yourname”才能与jquery一起发送。