【发布时间】:2017-09-06 10:29:27
【问题描述】:
我加载了我想通过 ajax JSON 请求从数据库中显示获取记录的视图。但它没有显示记录。
这是我的视图代码
<div class="col-md-6" id="hodm_table">
<table class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Task Name</th>
<th>Director</th>
<th>Duration</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach($result as $hodm) { ?>
<tr>
<td><?php echo $hodm->t_name;?></td>
<td><?php echo $hodm->director;?></td>
<td><?php echo $hodm->duration;?></td>
<td><?php echo $hodm->status;?></td>
<?php } ?>
</tbody>
</table>
</div>
</div>
<script type='text/javascript' language='javascript'>
$(document).ready(function(){
$.ajax({
url:"<?php echo base_url();?>digital/dashboard/dig_short_hodm_table",
type: 'POST',
dataType: 'JSON',
success:function (data) {
$('#hodm_table').html(data);
}
});
event.preventDefault();
});
</script>
这是我的模型
public function get_hodm()
{
return $this->db->get("hodm");
}
这是我的控制器
public function dig_short_hodm_table(){
$data['result']=$this->pojo->get_hodm();
return json_encode($data);
}
当我加载我的页面时,它会显示错误
Message: Undefined variable: result
我想在视图加载时从数据库中获取记录并显示在视图表中。
【问题讨论】:
-
在控制器函数@xr33dx中加载视图页面
-
@Parvez 不工作
标签: php mysql json ajax codeigniter