php - Not able to display data through ajax in codeigniter -


i want show restaurant after selecting area dropdown list. code did not show restaurant name , menu button of restaurant please tell me did mistake

its model code

function select_record($table, $where = null) {     $this->db->select();     if ($where) $this->db->where($where);     $this->db->from($table);     $query = $this->db->get();     //  echo $this->db->last_query();     return $query->result(); } 

controller code

public function get_rests()  {     $cit_id = $this->input->post('cit_id');     $area = $this->input->post('areaid');     $where = array(         'city_id' => $cit_id,         'city_area_id' => $area     );     $data = $this->bulk->select_record('restaurant', $where);     $html = '<div class="container" id="">                         <table align="centre" class="table table-condensed table-striped table-hover no-margin"style="width:70%" id="">                             <thread>                                 <tr style="width: 56%;">                                     <th> no. </th>                                     <th style=""> restaurant names </th>                                 </tr>                             </thread>                             <tbody>                             <th> <span value="'. $data[0]->restaurant_id . '" class="res_id"></span></th>                                 <th style=""> </th>                                 <th style=""> <span value="'. $data[0]->restaurant_name . '" class="res_id"></span> </th>                                 <th style="width: 1%" > <a href="<?php echo base_url(); ?>index.php/bulkrecipe_controller/bulk_recipe/<?php echo $row->restaurant_id; ?>"  class="btn btn-warning" <i class="glyphicon-edit"></i>see menu</a> </th>                             </tr>                             </tbody>                         </table>                     </div>';     echo json_encode(array(         'data' => $html     ));  } 

script code

function get_rests() {      var city_id = $('#city_id').val();     var area_id = $("#area_id").val();     $.ajax({         type: "post",         url: "<?=base_url();?>index.php/bulk_controller/get_rests",         data: {             cit_id: city_id,             areaid: area_id         },         datatype: 'json',         cache: false,         success: function (response) {             alert(response);             $('#restaurant').html(response.data);         }     }); } 

its view code

<div id="restaurant">   </div> 

when did alert(response.data);

     <div class="container" id="">         <table align="centre" class="table table-condensed table-striped table-hover no-margin"style="width:70%" id="">              <thread>                 <tr style="width: 56%;">                      <th>                          no.                      </th>                      <th style="">                          restaurant names                      </th>                  </tr>             </thread>             <tbody>   <th>                  <span value="1" class="res_id"></span></th>                     <th style="">                     </th>                      <th style="">                                   <span value="salten paper" class="res_id"></span>                      </th>                      <th style="width: 1%" >                         <a href="<?php echo base_url();?>index.php/bulkrecipe_controller/bulk_recipe/<?php echo $row->restaurant_id;?>"  class="btn btn-warning" <i class="glyphicon-edit"></i>see menu</a>                      </th>                  </tr>              </tbody>          </table>      </div> 

please tell me did mistake

you not putting response ajax properly. $('#restaurant').html(response.data); should be:

$('#restaurant').html(response); 

also change

url: "<?=base_url();?>index.php/bulk_controller/get_rests", 

to

url: "<?=base_url();?>index.php/bulk_controller/get_rests", 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -