how to use json_encode for my output?

Your question unclear

You could try some thing like

public function show_message($id)
{
    $this->db->select('status, message');
    $this->db->from('tbl_message');
    $this->db->where('MID', $id);
    $query = $this->db->get();

    return $query->row_array();
}

Json Controller Function

public function example() {
    $id = '1';

    $message = $this->model_name->show_message($id);

    echo json_encode($message);
}

View

$( document ).ready(function() {
   $(".load").click(function(e){
      $.ajax({
        url: "<?php echo base_url("controller/example");?>",
        type: "get",
        dataType: 'JSON',
        success: function(json){
            alert(json[message]);
            console.log(json);
        }
      });
   });
});

Browse More Popular Posts

Leave a Comment