【发布时间】:2017-05-15 06:15:14
【问题描述】:
我是 CodeIgniter 的新手我从这个控制器获取数据 控制器:
public function selectAll(){
$this->load->model('EmpModel');
$res=$this->EmpModel->selectAll();
if(count($res) > 0){
echo json_encode(Array("success"=>"1"));
}else{
echo json_encode(Array("success"=>"0"));
}
}
我想使用 $.each() 在视图中显示它 观点:
<table id="t_id">
<tr>
<th>id</th>
<th>name</th>
<th>email</th>
<th>pass</th>
</tr>
<tbody>
</table>
<button type="button" id="subBtn11" >CLICK</button>
$("#subBtn11").click(function (){
alert("ok");
$.ajax({
url:"<?php echo base_url('index.php/EmpCon/selectAll')?>",
method:"get",
dataType:"json",
data:{
},
success:function (data){
var arr=[];
var trHTML = '';
if(data.success==1){
$.each(data, function (i, item) {
trHTML += '<tr><td>' + data.id[i] + '</td><td>' + data.name[i] + '</td><td>' + data.email[i]+'</td><td>'+data.password+'</td></tr>';
});
$('#t_id').append(trHTML);
}else{
alert("wrong");
}
},
error:function(msg){
alert(msg.responseText);
}
});
});
我用谷歌搜索了这个查询,但没有得到任何令人满意的解释。提前致谢。
【问题讨论】:
-
你只是通过ajax返回成功键而已。
标签: jquery ajax codeigniter