Reputation: 690
I tried to show data by modal Bootstrap and also updates the data with ajax but it can not be done together, how to be able to display the data and update the data on codeigniter?
My views ajax
<a href="javascript:void(0)" onclick="show_note('<?php echo $row->id_note; ?>');">unread</a>
function show_note(id_note) {
$.ajax({
url : "<?php echo site_url('my_controll/note_update')?>/" + id_note,
type: "GET",
dataType: "JSON",
success: function(data)
{
$('#note').val(data.note);
$('#note_show').modal('show');
},
error: function (jqXHR, errorThrown)
{
alert('Error ajax');
}
});
}
Controllers
function note_update($id_note) {
$data = $this->M_model->detail_note($id_note);
echo json_encode($data);
}
Models
function detail_note($id_note) {
$this->db->set('status_note', '0');
$this->db->where('id_note', $id_note);
$this->db->update('table_note', $data);
$query = $this->db->select('*')
->from('table_note')
->where('id_note', $id_note)
->get();
return $query->row();
}
Upvotes: 0
Views: 2853
Reputation: 6969
Did you try like this..
Controller:
function note_update($id_note) {
$data = $this->M_model->detail_note($id_note);
echo json_encode($data);
}
Model :
function detail_note($id_note) {
$this->db->set('status_note',0);
$this->db->where('id_note', $id_note);
$this->db->update('table_note');
$query = $this->db->select('*')
->from('table_note')
->where('id_note', $id_note)
->get();
return $query->row_array();
}
Don't forget load url
helper and yor ajax must be like this..
<a href="javascript:void(0)" onclick="show_note('<?php echo $row->id_note; ?>');">unread</a>
function show_note(id_note) {
$.ajax({
url : "<?php echo base_url('my_controll/note_update');?>/"+id_note,
type: "GET",
dataType: "JSON",
success: function(data)
{
var data = JSON.parse(data);
$('#note').val(data.note);
},
complete: function(data){
$('#note_show').modal('show');
},
error: function (jqXHR, errorThrown)
{
alert('Error ajax');
}
});
}
Upvotes: 1