Im new to CodeIgniterIm receiving data from this controller Controller:
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"));
}
}
I want to show this with $ .each () view:
<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);
}
});
});
I looked at a Google request but did not get a satisfactory explanation. Thanks in advance.
source
share