I find it a little embarrassing to admit, but a few months ago I had asked the same question. Unfortunately, I failed to implement it with codeigniter back then.
If you're curious, you can check out my old question.
My current challenge involves updating selected data via modal bootstrap. However, before that can happen, the selected data must be passed into the modal bootstrap by an id, which is where I seem to be stuck at the moment.
UPDATE
I have made some improvements to my rather terrible code since my last attempt, but I still require some assistance.
This is how my view looks like:
<tbody id="showdata">
<?php foreach ($fo as $f) { ?>
<tr>
<td><?php echo $f->siteid ?></td>
<td><?php echo $f->sitename ?></td>
<td><?php echo $f->witel ?></td>
<td><?php echo $f->addr ?></td>
<td><?php echo $f->lat ?></td>
<td><?php echo $f->longi ?></td>
<td><a href="javascript:;" class="btn btn-info item-detail" data="<?php echo $f->siteid ?>">Details</a></td>
</tr>
<?php } ?>
Here's the js function I'm using:
$('#showdata').on('click', '.item-detail', function(){
var siteid = $(this).attr('data');
$('#myModal').modal('show');
$('#home').find('h3').text('Data Teknisi');
$.ajax({
type: 'ajax',
method: 'get',
url: '<?php echo base_url() ?>admin/getById',
data: {siteid: siteid},
async: false,
dataType: 'json',
success: function(data){
$('input[name=siteid]').val(data.siteid);
$('input[name=sitename]').val(data.sitename);
},
error: function(){
alert('Could not display data');
}
});
});
And this is my controller:
function getById(){
$result = $this->artikel->getById();
echo json_encode($result);
}
Additionally, here's the model:
public function getById(){
$siteid = $this->input->get('siteid');
$this->db->where('siteid', $siteid);
$query = $this->db->get('datek');
if($query->num_rows() > 0){
return $query->row();
}else {
return false;
}
}
While working on this, I encountered some errors in the console browser such as:
" Failed to load resource: the server responded with a status of 404 (Not Found)send @ jquery-1.12.3.js:10261",
or even this one:
"jquery-1.12.3.js:10261 GET http://localhost/ci/admin/getById?siteid=BPP194 404 (Not Found)send @ jquery-1.12.3.js:10261ajax @ jquery-1.12.3.js:9750(anonymous function) @ admin:576dispatch @ jquery-1.12.3.js:5226elemData.handle @ jquery-1.12.3.js:4878"