Codeigniter Ajax数据表显示错误
我引用了这个链接,使我的codeigniter datatable成为基于ajax的datatable 但它显示的是错误,而不是数据表中的数据 消息:未定义索引:长度 消息:未定义索引:开始 消息:未定义索引:绘制 请有人帮我删除这些错误 我的JqueryCodeigniter Ajax数据表显示错误,ajax,codeigniter,datatable,Ajax,Codeigniter,Datatable,我引用了这个链接,使我的codeigniter datatable成为基于ajax的datatable 但它显示的是错误,而不是数据表中的数据 消息:未定义索引:长度 消息:未定义索引:开始 消息:未定义索引:绘制 请有人帮我删除这些错误 我的Jquery $(document).ready(function(){ //Ajax Datatable //datatables var dataTable = $('#dataTables-suburb').Data
$(document).ready(function(){
//Ajax Datatable
//datatables
var dataTable = $('#dataTables-suburb').DataTable({
processing: true, //Feature control the processing indicator.
serverSide: true, //Feature control DataTables' server-side processing mode.
order: [], //Initial no order.
// Load data for the table's content from an Ajax source
ajax: {
url: "<?php echo site_url('admin/states/state_table_ajax')?>",
type: "POST"
},
//Set column definition initialisation properties.
columnDefs: [
{
targets: [ 0 ], //first column / numbering column
orderable: false, //set not orderable
},
],
});
});
提前感谢您。在您的控制器中
从
到
在你的模型中
从
到
按如下方式更改模型代码:
get_states_table()
在控制器中调用此函数:
$length = $_POST['length'];
$start = $_POST['start'];
get_states_table($country_id,$length,$start)
像这样:
get_states_table()
在哪里
显示您的Html和Jquery代码现在显示这一个,因为我在另一个函数中调用了ajax,在另一个函数中调用了视图。DataTables警告:表id=DataTables-Ajax错误。有关此错误的更多信息,请参阅他们提供的链接,该链接显示了错误的内容以及我们如何解决它。抱歉,无法解决我对此一无所知。我已经更新了视图jquery、控制器代码和模型代码。请检查您是否在模型的“获取状态”功能中返回任何内容?
if(isset($_POST['start']) && isset($_POST['draw']))
{
$no = $_POST['start'];
}else{
// need start and draw
die(); // some error
}
if($_POST["length"] != -1)
if(isset($_POST["length"]) && $_POST["length"] != -1)
public function get_states($country_id)
{
$order_column = array('id', 'state_name');
$this->db->select('id, state_name');
$this->db->from('tbl_states');
$this->db->where('country_id', $country_id);
//For Search value Datatable
if(isset($_POST['search']['value']))
{
$this->db->like('state_name', $_POST['search']['value']);
}
//For Order Datatable
if(isset($_POST['order']))
{
$this->db->order_by($this->order_column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}
else
{
$this->db->order_by('id', 'DESC');
}
$query = $this->db->get();
$result = $query->result_array();
return $result;
}
//Get Datatable
public function get_states_table($country_id,$length,$start)
{
$this->get_states($country_id);
if($length != -1)
{
$this->db->limit($length, $start);
$query = $this->db->where('country_id', $country_id, FALSE)
->get();
return $query->result_array();
}
}
function get_states_count_filtered($country_id)
{
$this->get_states($country_id);
$query = $this->db->where('country_id', $country_id, FALSE)
->get();
return $query->num_rows();
}
public function get_states_count($country_id)
{
$this->db->where('country_id', $country_id, FALSE)
->from('tbl_states');
return $this->db->count_all_results();
}
get_states_table()
$length = $_POST['length'];
$start = $_POST['start'];
get_states_table($country_id,$length,$start)