【发布时间】:2016-09-16 10:42:58
【问题描述】:
我有一个“坐在”表格内的表格
<form id="form">
<input type="submit" value="send" class="btn btn-w-m btn-primary" style="float: left;">Add transaction</input>
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<tr>
<th>Date</th>
<th>Name<br>(Last name, Firstname,<br>
or Business name)
</th>
<th>Address</th>
<th>Phone</th>
<th>Price with VAT</th>
<th>VAT</th>
<th>Transaction type</th>
<th>Currency</th>
<th>Installments</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="date" name="date"/></td>
<td><input type="text" name="name"/></td>
<td><input type="text" name="address"/></td>
<td><input type="text" name="phone"/></td>
<td><input type="text" name="price_with_vat"/></td>
<td>25%(from database)</td>
<td class="exclude"><select name="transaction_type">
<option>value1</option>
<option>value2</option>
<option>value3</option>
</select></td>
<td class="exclude"><select name="currency">
<option>Euro</option>
<option>USD</option>
<option>Pound</option>
</select></td>
<td class="exclude"><select name="installments">
<option>Yes</option>
<option>No</option>
</select></td>
</tr>
</tbody>
我想要的是选择所有输入值并将 Ajax 请求发送到 php 端。问题是在我的 jquery 函数(以下代码)中,我无法收集所有输入。虽然我有一个preventDefault 页面,但仍然会刷新。
var request;
$('#form').submit(function(event){
if (request){
request.abort();
}
var form = $(this)
var $inputs = $form.find("input, select, button, textarea");
var serializedData = $form.serialize();
$inputs.prop("disabled", true);
console.log(serializedData);
event.preventDefault();
});
【问题讨论】:
-
可以使用数据:$('#formName').serialize()。见链接api.jquery.com/serialize
-
我对@987654325@进行了编辑,请看一下(见最后一句话)
-
var
form = $(this)应该是$form
标签: javascript php jquery ajax forms