收到错误"数据表警告:表 id=example - 为第 1 行第 1 列请求的未知参数"1"。有关此错误的更多信息,请参阅 http://datatables.net/tn/4" 从 ajax api 调用加载数据时,从后端收到的 json 如下所示
[{"CustomerName":"Dinesh","product":"23234","perticulars":"wrwer","AddressOfCustomer":"wrew`","ContactNumbers":"jhkjhb"}, {"CustomerName":"dd","product":"dfsdfs","perticulars":"fsdfs","AddressOfCustomer":"sdfsdf","ContactNumbers":"fsfsf"}, {"CustomerName":"Pratik","product":"toothbrush","perticulars":"6 inch","AddressOfCustomer":"shreedhama white rose","ContactNumbers":"9949634396"}]
正在为其填充表数据的 HTMLdiv 标记的代码段如下所示。
<table id="example" class="display" align="center" vertical-align="middle"; cellspacing="0" width="100%">
<thead>
<tr>
<th>Customer Name</th>
<th>Product</th>
<th>Perticulars</th>
<th>Address of customer.</th>
<th>Contact number</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Customer Name</th>
<th>Product</th>
<th>Perticulars</th>
<th>Address of customer.</th>
<th>Contact number</th>
</tr>
</tfoot>
</table>
下面是我正在做的 ajax 调用,并且在成功函数中尝试从 json 填充数据
$.ajax({
url:'AddQuotation',
type:'get',
success:function(data){
alert(data);
var resultTable = $('#example').DataTable({
"columns": [
{ data: "CustomerName" },
{ data: "product" },
{ data: "perticulars" },
{ data: "AddressOfCustomer" },
{ data: "ContactNumbers" }
],
"destroy": true,
"dom": 'lrtip'
} );
resultTable.rows.add(data1).draw();
dataSet = data;
},
error:function(){
alert('error');
}
});
data
包含对象数组的对象。
{"data": [{"CustomerName":"Dinesh","product":"23234","perticulars":"wrwer","AddressOfCustomer":"wrew`","ContactNumbers":"jhkjhb"}, {"CustomerName":"dd","product":"dfsdfs","perticulars":"fsdfs","AddressOfCustomer":"sdfsdf","ContactNumbers":"fsfsf"}, {"CustomerName":"Pratik","product":"toothbrush","perticulars":"6 inch","AddressOfCustomer":"shreedhama white rose","ContactNumbers":"9949634396"}]}
一个工作演示。
就我而言,我只是更改了代码中的以下内容和错误
数据表警告:表 id=引导数据表2 - 请求第 0 行的未知参数"0"。有关此错误的详细信息,请参阅 http://datatables.net/tn/4
不见了:
从:
<tbody>
@foreach (var item in Model.HRMS_Tbl_ExpenseClaimModelList)
{
<tr>
@if (item.Approved == "1")
{
<td>@item.Date</td>
<td>@item.Date</td>
<td>@item.Type</td>
<td>@item.Amount</td>
}
</tr>
}
</tbody>
自:
<tbody>
@foreach (var item in Model.HRMS_Tbl_ExpenseClaimModelList)
{
if (item.Approved == "1")
{
<tr>
<td>@item.Date</td>
<td>@item.Date</td>
<td>@item.Type</td>
<td>@item.Amount</td>
</tr>
}
}
</tbody>