ajax - 如何解决这个错误(Uncaught TypeError: Cannot read property 'aDataSort' of undefined)?
问题描述
我该如何解决这个问题,这是我的代码:
<html>
<head>
<script>
$(function() {
$('#pemohon-table').DataTable({
processing: true,
serverSide: true,
ajax: 'http://localhost:8000/pemohon/get_datatable'
});
});
</script>
</head>
<body>
<table id="pemohon-table" class="table">
<thead>
<tr>No</tr>
<tr>Nomor Permohonan</tr>
<tr>Tanggal Permohonan</tr>
<tr>Nama</tr>
<tr>Tanggal Lahir</tr>
<tr>Status</tr>
</thead>
</table>
</body>
我得到了这个错误:
未捕获的类型错误:无法读取未定义的属性“aDataSort”
我不知道具体是什么问题,请帮助我。谢谢。
解决方案
如果你使用数据表,也许你可以这样设置:
在控制器中,您制作 getData 功能
public function getData(Request $request){
$pemohon = YourModel::select('your_coloum_in_database.*');
return Datatables::of($pemohon)
->make(true);
}
在您看来,您可以这样调用:
<table class="table table-bordered table-hover table-striped w100" cellspacing="0" id="datatable"></table>
<script>
$('#datatable').dataTable({
processing: true,
serverSide: true,
ajax: {
method: 'POST',
url : '{{ route('your_route') }}',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
},
columns : [
{title: 'No', data: 'no, name: 'no', defaultContent: '-', class: 'text-center'},
{title: 'Nomor Permohonan', data: 'nomor_permohonan', name: 'nomor_permohonan', defaultContent: '-', class: 'text-center'},
{title: 'Tanggal Permohonan', data: 'tanggal_permohonan', name: 'tanggal_permohonan', defaultContent: '-', class: 'text-center'},
{title: 'Nama', data: 'nama', name: 'nama', defaultContent: '-', class: 'text-center'},
{title: 'Tanggal Lahir', data: 'tanggal_lahir', name: 'tanggal_lahir', defaultContent: '-', class: 'text-center'},{title: 'Status', data: 'status', name: 'status', defaultContent: '-', class: 'text-center'},
</script>
推荐阅读
- javascript - jquery .val('') 不起作用,留下 0 而不是清除字段
- javascript - 无法解决反应和节点应用程序中的cors错误
- android - Chromecast 的错误代码 2154 的定义是什么?
- powershell - 使用 Powershell Get-PnPFile 和 Add-PnPFile 将 SharePoint 下载/上传文件作为流
- django - 如何从 consumer.py django 访问用户信息?
- pyinstaller - Cx_Oracle 和 Pyinstaller
- c++ - 指向其他许多对象的有效成员指针
- ace-editor - 没有在光标所在的位置输入字符
- javascript - javascript中的哪个命令单击按钮name =“form:j_id15”?
- android - 如何在我的 Android 应用中仅播放来自 youtube 频道的直播视频?