mysql - Displaying data from database from Controller to View using jQuery AJAX request CodeIgniter without refereshing the page -


how can load particular portion of page in codeigniter? ajax working reloads views calling controller name(like header, body, footer) want reload body, how can separate code work properly.

its ajax code

$('label#showdata').click(function(){            var fromdate =document.getelementbyid('fromdate').value;           var todate = $(this).val();           var datastring = 'fromdate='+ fromdate+'todate='+todate;              $.ajax({         type: "post",         url: "https://chotigaadi.com/myadmin/references",         data: datastring,         cache: false,         success: function(html)         {         $("div#result").html(html).show();         //alert(datastring);         }         });       }); 

its view

<div class="col s12 m12">     <form action="<?php echo base_url();?>myadmin/exportcsv" method="post">         <div class="col s12 m3">             <h5 class="center" style="color:green;font-weight:bold;">registered members list</h5>         </div>         <div class="col s12 m2">             <div class="input-field col s12">                 <label for="date"> <i class="fa fa-calendar"></i> select date below:</label>                 </br>                 <input name="fromdate" id="fromdate" type="date" class="datepicker" required>              </div>         </div>         <div class="col s12 m3">             <div class="input-field col s12">                 <label for="date"> <i class="fa fa-calendar"></i> select date below:</label>                 </br>                 <input name="todate" id="todate" type="date" class="datepicker" required>              </div>          </div>         <div class="col s12 m4">             <div class="col s6">                 <label id="showdata" class="btn waves-effect waves-light orange right" value="show">show results</label>             </div>             <div class="col s6">                 <input type="submit" id="datesubmit" class="btn waves-effect waves-light green right" value="export data" />             </div>         </div>     </form>     <div id="result">         <table class="highlight">             <thead>                 <tr style="background-color:#ccc;">                     <th data-field="name">id</th>                     <th data-field="name">referee</th>                     <th data-field="rname">reference</th>                     <th data-field="email">email</th>                     <th data-field="phone">phone</th>                  </tr>             </thead>             <tbody>                 <?php                        foreach ($results $row)                       {?>                     <tr style="">                          <td>                             <?php echo $row->firstname;?>                         </td>                         <td>                             <?php echo $row->name; ?>                         </td>                         <td>                             <?php echo $row->email; ?>                          </td>                         <td>                             <?php echo $row->phone; ?>                         </td>                     </tr>                     <?php }?>             </tbody>         </table>     </div> </div> 

my controller code:

function references(){         if (!$this->check_user()) {             redirect('myadmin/login/');         }         else         {             if(isset($_post['fromdate']) && isset($_post['todate']))                {                  $fromdate=new datetime(str_replace("-","",$_post['fromdate']));                 $fromdate=$fromdate->format('y-m-d h:i:s');                 $todate=new datetime(str_replace("-","",$_post['todate']));                 $todate=$todate->format('y-m-d h:i:s');                }                else                 {                 $fromdate=new datetime('2015-12-10 14:28:27');                 $fromdate=$fromdate->format('y-m-d h:i:s');                  $todate=new datetime(date("y-m-d"));                 $todate=$todate->format('y-m-d h:i:s');                 }               $config = array();             $config["base_url"] = base_url() . "myadmin/references";             $config["total_rows"] = $this->myadmin_model->record_count($fromdate, $todate);             $config["per_page"] = 8;             $config["uri_segment"] = 3;              $this->pagination->initialize($config);              $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;             $data["results"] = $this->myadmin_model->fetch_userdata($config["per_page"], $page, $fromdate, $todate);             $data["links"] = $this->pagination->create_links();            $this->load->view('/admin/myadminheader');         $this->load->view('/admin/myadmin',$data);         $this->load->view('/admin/myadminfooter');         }     } 

i want reload view $this->load->view('/admin/myadmin',$data); ajax how can this?

if want change middle part not load header , footer in ajax calling function.

remove these 2 lines:

$this->load->view('/admin/myadminheader');  $this->load->view('/admin/myadminfooter'); 

it only:

$this->load->view('/admin/myadmin',$data);  

this return middle part not header footer in ajax response.

side note:

if using function directly need pass param ajax request checking either request ajax or not.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

dataset - MPAndroidchart returning no chart Data available -

post - imageshack API cURL -