我在表格中有下表
<form>
<table id="Table1" class="appendGrid ui-widget">
<thead class="ui-widget-header">
<tr>
<td class="ui-widget-header" style="width: 32px;"></td>
<td class="ui-widget-header">SupCo</td>
<td class="ui-widget-header">Number</td>
</tr>
</thead>
<tbody class="ui-widget-content">
<tr id="tblAppendGrid_Row_1">
<td class="ui-widget-content first">1</td>
<td class="ui-widget-content">
<input type="text" id="tblAppendGrid_SupCo_1" name="SupCo" maxlength="100" style="width: 160px;"></td>
<td class="ui-widget-content">
<input type="text" id="tblAppendGrid_Number_1" name="Number" maxlength="4" style="width: 40px;"></td>
</tr>
<tr id="tblAppendGrid_Row_2">
<td class="ui-widget-content first">2</td>
<td class="ui-widget-content">
<input type="text" id="tblAppendGrid_SupCo_2" name="SupCo" maxlength="100" style="width: 160px;"></td>
<td class="ui-widget-content">
<input type="text" id="tblAppendGrid_Number_2" name="Number" maxlength="4" style="width: 40px;"></td>
</tr>
<tr id="tblAppendGrid_Row_3">
<td class="ui-widget-content first">3</td>
<td class="ui-widget-content">
<input type="text" id="tblAppendGrid_SupCo_3" name="SupCo" maxlength="100" style="width: 160px;"></td>
<td class="ui-widget-content">
<input type="text" id="tblAppendGrid_Number_3" name="Number" maxlength="4" style="width: 40px;"></td>
</tr>
<button role="button" class="ui-button" id="btnSave" type="button"></button>
</tbody>
</table>
</form>
我正在尝试读取每一行(tr)并使用 ajax 函数提交它。
$('#btnSave').button().click(function () {
var rowData = $(document.forms[0]).serializeArray();
$.each(rowData, function (i, field) {
var oData = {
"SupCo": field.SupCo.value,
"Number": field.Number.value
};
$.ajax({
type: 'post',
url: "./api/updateDb?Id=" + Id +"&",
data: oData,
Sucess: alert("Record UdpateSucessfully.")
});
});
我遇到的问题是,当我尝试 serlializeArray 时,它只是一个长字符串并且不保存在对象中。我的目标是将每一行作为一个对象或读取最近的 tr,这样我就可以将它提交到更新 db。任何想法我该怎么做?帮忙请eeeee