嗨我有一个带有ajax的数据表,它调用一个函数来获取并在控制器中显示结果。
我的问题是它只能在索引控制器中使用,例如链接。
http://localhost/zcaexample/admin/feetype
控制器:
public function index() {
$this->load->view('feetype');
}
但是当您在具有相同视图的另一个控制器中访问它时,例如
public function sample() {
$this->load->view('feetype');
}
链接为:
http://localhost/zcaexample/admin/feetype/sample
我的Jquery:
var manageFeetypeTable; // global variable
$(document).ready(function() {
manageFeetypeTable = $("#manageFeetypeTable").DataTable({
'ajax' : 'feetype/fetchFeetypeData',
'order': []
});
});
我的控制器:它有ajax的结果。
public function fetchFeetypeData()
$feetypeData = $this->model_feetype->fetchFeetypeData();
$result = array('data' => array());
$x = 1;
foreach ($feetypeData as $key => $value) {
$button = '<!-- Single button -->
<div class="btn-group">
<button type="button" class="btn btn-primary" style="text-align:left;" dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Action <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a type="button" class="btn btn-default" style="text-align:left;" data-toggle="modal" data-target="#editFeetypeModal" onclick="editFeetype('.$value['feetype_id'].')"> <i class="glyphicon glyphicon-edit"></i> Edit</a></li>
<li><a type="button" class="btn btn-default" style="text-align:left;" data-toggle="modal" data-target="#removeFeetypeModal" onclick="removeFeetype('.$value['feetype_id'].')"> <i class="glyphicon glyphicon-trash"></i> Remove</a></li>
</ul>
</div>';
$result['data'][$key] = array(
$x,
$value['feetype_name'],
$value['feetype_role'],
$value['feetype_dateadded'],
$button
);
$x++;
} // /for each
echo json_encode($result);
}
你能告诉我什么是错的或有什么问题吗?