我在ajax加载表单上遇到了serialize()的一些问题。
jQuery代码:
$(document).on("submit", this.id, function(e) {
e.preventDefault();
var frm = e.target.id;
var frmData = $("#"+frm).serialize();
console.log(frm);
console.log(frmData);
});
控制台输出:
表单本身(bootstrap):
<div class="tab-pane active" id="logintab">
<div class="well">
<form class="form-horizontal" id="loginForm">
<div class="control-group">
<label class="control-label" for="inputEmail">E-mail adres</label>
<div class="controls">
<input type="email" id="inputEmail" value="info@domainname.com" placeholder="E-mail adres" data-validation-email-message="Not a valid e-mail address" required>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input type="password" id="inputPassword" value="test" placeholder="Wachtwoord" data-validation-required-message="Not a valid password" required>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn submitbtn"><i class="icon-signin"></i> Inloggen</button>
</div>
</div>
</form>
</div>
</div>
答案 0 :(得分:8)
表单元素需要具有要序列化的名称和值,您的元素没有名称。如果添加名称:
<input type="email" name="email" id="inputEmail" ......
它运作得很好: