Welcome Guest, Not a member yet? Register   Sign In
How to get JSON data in table - Codeigniter

(This post was last modified: 09-07-2018, 01:56 AM by jaydevvara.)

Hello I want to display data on click without refresh page in codeigniter, I got data in JSON but how to display in table view, so here is my code so please help me.

Here Is My Controller:
public function get_event_date() {
   $start_event = $this->input->POST("start_event");
   $end_event = $this->input->POST("end_event");
   $events = $this->main_model->getallevent($start_event,$end_event);
   $data_events = array();
   foreach ($events->result() as $r) {
       $data_events[] = array(
           "id" => $r->id,
           "title" => $r->title,
           "start_event" => $r->start_event,
           "end_event" => $r->end_event,
   echo json_encode(array("events" => $data_events));

Here Is My Model:
public function getallevent($start_event,$end_event)
   return $this->db->where("start_event >=",$start_event)->where("end_event <=", $end_event)->get("events");
Here My ajax:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
   $(document).ready(function () {
// code to get all records from table via select box
$("#getdata").click(function () {

   var event_type = $('#event_type').val();
   var start_event = $('#start_event').val();
   var end_event = $('#end_event').val();


               url: "<?php echo base_url('welcome/get_event_date'); ?>",
               type: "POST",
               dataType: "json",
               data: {"event_type": event_type, "start_event": start_event, "end_event": end_event},
               success: function (data) {
               error: function (data) {
                   // do something

Here is My View:
<table id="example1" class="table table-bordered table-striped">
           <th>Event Type</th>
           <th>Event Name</th>

   foreach ($allevents as $get) {

               <td><?php echo $get->start_event; ?></td>
               <td><?php echo $get->event_type; ?></td>
               <td><?php echo $get->title; ?></td>


Messages In This Thread
How to get JSON data in table - Codeigniter - by jaydevvara - 09-07-2018, 01:55 AM

Theme © iAndrew 2016 - Forum software by © MyBB