假设我有一个这样的表:
<table id="parameters" width="100%" border="1">
<thead>
<tr>
<th>Date</th>
<th>Identity</th>
<th>Names</th>
<th>Quantity</th>
<th>Concept</th>
<th>Select</th>
</tr>
</thead>
<tbody>
<tr>
<td>2016-08-10<input type="hidden" name="date[]" value="2016-08-10"></td>
<td>12345678<input type="hidden" name="identity[]" value="12345678"></td>
<td>Pepito Perez</td>
<td>2.5<input type="hidden" name="value[]" value="2.5"></td>
<td>daytime<input type="hidden" name="concept[]" value="1"></td>
<td><input type="checkbox" name="check[]" value="12345678"></td>
</tr>
<tr>
<td>2016-08-10<input type="hidden" name="fecha[]" value="2016-08-10"></td>
<td>24681012<input type="hidden" name="identity[]" value="24681012"></td>
<td>Camilo Sanchez</td>
<td>2.5<input type="hidden" name="value[]" value="2.5"></td>
<td>daytime<input type="hidden" name="concept[]" value="1"></td>
<td><input type="checkbox" name="check[]" value="24681012"></td>
</tr>
<tr>
<td>2016-08-10<input type="hidden" name="fecha[]" value="2016-08-10"></td>
<td>369121518<input type="hidden" name="identity[]" value="369121518"></td>
<td>Pepito Perez</td>
<td>2.5<input type="hidden" name="value[]" value="2.5"></td>
<td>daytime<input type="hidden" name="concept[]" value="1"></td>
<td><input type="checkbox" name="check" value="369121518"></td>
</tr>
</tbody>
</table>
该表是根据查询生成的,复选框的id是每个员工的身份值。
我想从数组中选中的复选框中获取隐藏输入的值,然后通过ajax发送该数据,然后将它们保存在数据库中:
//Here, when clicking the button confirm searches the table that are marked
confirm.on('click', function(){
//Save in result inputs with marked checkbox
$("#parameters tbody tr td input[name=check]:checked").each(function(){
var result = [];
$(this).closest('tr').find('input[type="hidden"]').each(function(){
result.push($(this).serializeArray());
});
//sending the object by ajax
$.ajax({
type: "POST",
url: getBaseUri()+'/payroll/createAll/',
data: {datas: result},
cache: false,
success: function (response) {
var table = tableConfirm;
var url = table.data('source');
clearFom();
table.dataTable().fnReloadAjax(url);
},
error: function (response) {
console.log(response);
}
});
});
我想知道我做错了什么,以及是否有更好的方法通过ajax将数据存储到数据库中,因为我收到了这样的对象:
$datas =
Array
(
[0] => Array
(
[0] => Array
(
[name] => date
[value] => 2016-08-10
)
)
[1] => Array
(
[0] => Array
(
[name] => identity
[value] => 11434058
)
)
[2] => Array
(
[0] => Array
(
[name] => company
[value] => 1
)
)
[3] => Array
(
[0] => Array
(
[name] => cc
[value] => 2
)
)
[4] => Array
(
[0] => Array
(
[name] => value
[value] => 6
)
)
[5] => Array
(
[0] => Array
(
[name] => qov
[value] => 1
)
)
[6] => Array
(
[0] => Array
(
[name] => concept
[value] => 3
)
)
[7] => Array
(
[0] => Array
(
[name] => land
[value] => 1
)
)
)
我需要将此数组保存在数据库中,但我无法做到。
答案 0 :(得分:-1)
.serializeArrya()
是的,我将.val()
改为{{1}}并运行。