我使用了codeigniter relative_time helper created by yoeran。在ajax post中我调用控制器中的函数来返回相对时间和管理员名称。但相对时间alwayas返回null。是帮助者没有在ajax帖子中调用?
这里是我的ajax代码:
$.ajax({
type: "POST"
, url: baseurl +"admin/get_last_change/document"
, dataType: "json"
, data: {
id: $(".page-heading small").attr('data-document-id')
}
, success: function (result) {
$('#last-change').html(result.data);
console.log(result.data);
}
});
这里是我在控制器中的功能:
function get_last_change($keyword){
$id = $_POST['id'];
$where = array('target_id' => $id);
if($keyword == 'document'){
$result = $this->Admin_Model->get_task_admin(12, $where);
$admin_name = $result->row('admin_account_name');
$last_change = relative_time($result->row('created_at'));
$data = "Last Change : ".$last_change." by <span class='text-primary'>".$admin_name."</span>";
$output = array('data' => $data);
}
echo json_encode($output);
}
$ result的结果:
{"id":"12","created_at":"2016-05-17 09:52:14","admin_account_name":"Ibnu Habibie","task_name":"Add Content"}