gpt4 book ai didi

javascript - DataTables 警告 : table id=example - Requested unknown parameter '1' for row 1, 第 1 列

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:26:35 38 4
gpt4 key购买 nike

从 ajax api 调用 json 加载数据时出现错误“DataTables 警告:表 id=example - 为第 1 行第 1 列请求了未知参数‘1’。有关此错误的更多信息,请参阅 http://datatables.net/tn/4”从后端收到如下

[{"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"}]

填充表格数据的 HTML div 标签片段如下。

         <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"}]}

工作 DEMO .

关于javascript - DataTables 警告 : table id=example - Requested unknown parameter '1' for row 1, 第 1 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41531975/

38 4 0