jquery数据表don';t show data显示ajax错误
我想使用jquery datatable和ajax显示mysql表数据。但它会显示一条错误消息。 我的代码有问题吗? 这是我的控制器jquery数据表don';t show data显示ajax错误,jquery,ajax,codeigniter,datatables,Jquery,Ajax,Codeigniter,Datatables,我想使用jquery datatable和ajax显示mysql表数据。但它会显示一条错误消息。 我的代码有问题吗? 这是我的控制器 public function fetch_data() { $this->load->model('base_model'); $fetch_data=$this->base_model->make_datatables(); $data=array(); foreach($fetch_data as $
public function fetch_data()
{
$this->load->model('base_model');
$fetch_data=$this->base_model->make_datatables();
$data=array();
foreach($fetch_data as $row)
{
$sub_array=array();
$sub_array[]=$row->id;
$sub_array[]=$row->firstName;
$sub_array[]=$row->lastName;
$sub_array[]=$row->gender;
$sub_array[]=$row->address;
$sub_array[]=$row->dob;
$sub_array='<button type="button" name="update" id="'.$row->id.'" class="btn btn-warning">Update</button>';
$sub_array='<button type="button" name="delete" id="'.$row->id.'" class="btn btn-danger">Delete</button>';
$data[]=$sub_array;
}
$output=array(
'draw'=>intval($_POST["draw"]),
'recordsTotal'=>$this->base_model->get_all_data(),
"recordsFiltered" => $this->crud_model->get_filtered_data(),
"data" => $data
);
echo json_encode($output);
}
公共函数fetch_data()
{
$this->load->model('base_model');
$fetch_data=$this->base_model->make_datatables();
$data=array();
foreach($fetch_data as$row)
{
$sub_array=array();
$sub_数组[]=$row->id;
$sub_array[]=$row->firstName;
$sub_array[]=$row->lastName;
$sub_array[]=$row->gender;
$sub_数组[]=$row->address;
$sub_array[]=$row->dob;
$sub_array='Update';
$sub_array='Delete';
$data[]=$sub_数组;
}
$output=array(
'draw'=>intval($_POST[“draw”]),
'recordsTotal'=>this->base\u model->get\u all\u data(),
“recordsFiltered”=>this->crud\u model->get\u filtered\u data(),
“数据”=>$data
);
echo json_编码($output);
}
这是我的查看代码
$(document).ready(function(){
var dataTable=$('#user_data').dataTable({
"processing":true,
"serverSide":true,
"order":[],
"ajax":{
url:"<?php echo base_url().'base/fetch_data'?>",
type:"POST",
dataType:"json"
},
"columnDefs":[
{
"target":[0,3,4],
"orderable":false
}
]
});
});
$(文档).ready(函数(){
var dataTable=$(“#用户_数据”).dataTable({
“处理”:对,
“服务器端”:正确,
“订单”:[],
“ajax”:{
url:“”,
类型:“POST”,
数据类型:“json”
},
“columnDefs”:[
{
“目标”:[0,3,4],
“可订购”:false
}
]
});
});
使用jquerydatabale和ajax
控制者:
public function ajax_get_records() //jquerydatatable for static columns and rows
{
$arrayCount = 3;
$json = [
[
"Tiger Nixon",
"System Architect",
"Edinburgh",
"5421",
"2011/04/25",
"$320,800"
],
[
"Garrett Winters",
"Accountant",
"Tokyo",
"8422",
"2011/07/25",
"$170,750"
],
];
$columns = [
"Name",
"Position",
"Office",
"Extn",
"Start date",
"Salary"
];
$ajax_data['total'] = intval(3);
$ajax_data['recordsFiltered'] = intval(3);
$ajax_data['columns'] = $columns;
$ajax_data['data'] = $json;
header('Content-Type: application/json');
echo json_encode($ajax_data);
}
视图:
细节
名称
位置
办公室
Extn。
开始日期
薪水
使用jquerydatabale和ajax
控制者:
public function ajax_get_records() //jquerydatatable for static columns and rows
{
$arrayCount = 3;
$json = [
[
"Tiger Nixon",
"System Architect",
"Edinburgh",
"5421",
"2011/04/25",
"$320,800"
],
[
"Garrett Winters",
"Accountant",
"Tokyo",
"8422",
"2011/07/25",
"$170,750"
],
];
$columns = [
"Name",
"Position",
"Office",
"Extn",
"Start date",
"Salary"
];
$ajax_data['total'] = intval(3);
$ajax_data['recordsFiltered'] = intval(3);
$ajax_data['columns'] = $columns;
$ajax_data['data'] = $json;
header('Content-Type: application/json');
echo json_encode($ajax_data);
}
视图:
细节
名称
位置
办公室
Extn。
开始日期
薪水
请针对您的问题尝试此解决方案:
<html>
<title>Details</title>
<head>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/jquery.dataTables.min.js"></script>
<script type="text/javascript">
base_url = '<?=base_url()?>';
</script>
</head>
<body>
<table id="user_data" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<td colspan="6" align="center">
<div style="float:left">
<a title="uploads" href="<?php echo base_url();?>xlsimport/uploads">
<img src="<?php echo base_url();?>images/insert.png" height="25px" width="30px"></a>
</div>
</td>
</tr>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Extn.</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody></tbody>
</table>
</body>
</html>
细节
基本url=“”;
名称
位置
办公室
Extn。
开始日期
薪水
Datatable的脚本:
$(文档).ready(函数(){
$('#用户数据')。数据表({
“命令”:错误,
“bProcessing”:true,
“bServerSide”:正确,
“sAjaxSource”:基本url+“xlsimport/ajax\u获取记录”,
“sPaginationType”:“完整编号”,
“sDom”:“t”,
“fnServerData”:函数(sSource、aoData、fnServerData回调)
{
$.ajax
({
“数据类型”:“json”,
'type':'POST',
“url”:sSource,
“数据”:aoData,
“beforeSend”:函数(){
如果(!$('.se pre con')。是(':visible')){
}
},
"成功":,
“完成”:函数(){
}
});
},
“语言”:{
“SLENGHMENU”:“每页记录”,
“sZeroRecords”:“无可用数据”,
“数据处理”:”
},
});
} );
注意:请访问此JSFIDLE以供参考请针对您的问题尝试此解决方案:
<html>
<title>Details</title>
<head>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/jquery.dataTables.min.js"></script>
<script type="text/javascript">
base_url = '<?=base_url()?>';
</script>
</head>
<body>
<table id="user_data" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<td colspan="6" align="center">
<div style="float:left">
<a title="uploads" href="<?php echo base_url();?>xlsimport/uploads">
<img src="<?php echo base_url();?>images/insert.png" height="25px" width="30px"></a>
</div>
</td>
</tr>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Extn.</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody></tbody>
</table>
</body>
</html>
细节
基本url=“”;
名称
位置
办公室
Extn。
开始日期
薪水
Datatable的脚本:
$(文档).ready(函数(){
$('#用户数据')。数据表({
“命令”:错误,
“bProcessing”:true,
“bServerSide”:正确,
“sAjaxSource”:基本url+“xlsimport/ajax\u获取记录”,
“sPaginationType”:“完整编号”,
“sDom”:“t”,
“fnServerData”:函数(sSource、aoData、fnServerData回调)
{
$.ajax
({
“数据类型”:“json”,
'type':'POST',
“url”:sSource,
“数据”:aoData,
“beforeSend”:函数(){
如果(!$('.se pre con')。是(':visible')){
}
},
"成功":,
“完成”:函数(){
}
});
},
“语言”:{
“SLENGHMENU”:“每页记录”,
“sZeroRecords”:“无可用数据”,
“数据处理”:”
},
});
} );
注意:请访问此JSFIDLE以供参考您在警报对话框中访问过吗?按照页面诊断部分中的建议进行操作。是否仅将jquerydatatable与ajax一起使用,还是将jquerydatatable与ajax和服务器端一起使用。实际上,您在控制器中使用了服务器端数据表