在Web窗体应用程序中使用WebMethod时出现以下错误:
DataTables警告:表格ID = bootstrap-data-table-无效的JSON 响应。有关此错误的更多信息,请参见 http://datatables.net/tn/1
在尝试在DataTables表中显示我的数据时,在我的Jquery代码中单击按钮时会发生这种情况。谁能告诉我我所缺少的吗?
jQuery:
document.getElementById("openReqMenuButton").onclick = function () {
jQuery(document).ready(function () {
jQuery('#bootstrap-data-table').DataTable({
"processing": true,
"serverSide": true,
'searching': true,
'sort': true,
"ajax": {
"url": "/Pages/Requisitions.aspx/GetOpenRequisitionData",
"type": "POST"
},
"columns": [
{ 'data': 'ReqId' },
{ 'data': 'RequisitionTitle' },
{ 'data': 'City' },
{ 'data': 'Country', },
{ 'data': 'DateCreated' },
]
});
});
};
HTML
<table id="bootstrap-data-table" class="display" style="width:100%">
<thead>
<tr>
<th class="sorting" tabindex="0" aria-controls="bootstrap-data-table" rowspan="1" colspan="2">ReqId</th>
<th class="sorting" tabindex="0" aria-controls="bootstrap-data-table" rowspan="1" colspan="2">Requisition Title</th>
<th class="sorting" tabindex="0" aria-controls="bootstrap-data-table" rowspan="1" colspan="2">City</th>
<th class="sorting" tabindex="0" aria-controls="bootstrap-data-table" rowspan="1" colspan="2">Country</th>
<th class="sorting" tabindex="0" aria-controls="bootstrap-data-table" rowspan="1" colspan="2">Date Created</th>
</tr>
</thead>
</table>
答案 0 :(得分:0)
尝试添加tbody标签。我认为这对于DataTables是必需的:
var rgx = /(\B(".+?")\B|\B('.+?')\B|\B(`.+?`)\B)/g;
var str = `"Lorem ipsum dolor sit amet", consectetur adipisicing elit, "'sed do eiusmod tempor,'" incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, \`quis nostrud\` exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. \`Duis aute irure dolor\` in "reprehenderit in voluptate" velit esse cillum 'dolore eu fugiat nulla' pariatur. `;
var sub = ``;
var res = str.replace(rgx, sub);
console.log(res);