我在this tutorial之后使用带有CodeIgniter的DataTables。
当我加载我的视图时,我在控制台中收到错误:
Type Error: 1 is undefined in jquery.dataTables.min.js 49:323
我的控制器代码是:
public function index()
{
if($this->session->userdata('logged_in'))
{
$this->load->library('table');
$tmpl = array('table_open' => '<table id="doc_table"">');
$this->table->set_template($tmpl);
$this->table->set_heading('TMT_PK_Key', 'Name');
$this->load->view('doctor');
}
else
{
redirect('home');
}
}
function getDocData()
{
$this->load->library('Datatables');
$this->datatables
->select('TMT_PK_Key, Name')
->from('Doctor_Basic');
//->join('Doctor_Email', 'Doctor_Basic.TMT_PK_key = Doctor_Email.TMT_PK_key')
//->select('Email')
//->join('Doctor_Mobile', 'Doctor_Basic.TMT_PK_key = Doctor_Mobile.TMT_PK_key')
//->select('Mobile');
echo $this->datatables->generate();
}
}
我的观看代码(有些代码像js调用一样被省略):
<html>
<body>
<?php echo $this->table->generate(); ?>
</body>
</html>
JS
jQuery(document).ready(function () {
var oTable = jQuery('#doc_table').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": '/ci/doctor/getDocData',
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayStart ": 100,
"oLanguage": {
"sProcessing": "<img src='/ci/images/loading.gif'>"
},
'fnServerData': function (sSource, aoData, fnCallback) {
jQuery.ajax
({
'dataType': 'json',
'type': 'POSt',
'url': sSource,
'data': aoData,
'success': fnCallback
});
},
});
});
返回的数据(检查元素=&gt;网络=&gt;响应):
draw:0
recordsTotal:1331
recordsFiltered:1331
data:Array
0:Object
TMT_PK_Key:"TMTPK"
Name:"ABC"
我试过在论坛上寻找但无法找到解决方案。 任何帮助将受到高度赞赏。