Trying to do a data search with codeigniter 3, ajax. Here is my ajax:

$('input:radio').on('change',function(){ var value = $(this).data('val'); alert(value); $.ajax({ method:"POST", url:"main/tur_search", data:{value:value}, }).done(function(){ $('.load').load('tur_search'); }); 

But where ajax sends data:

  public function tur_search(){ $keyword = $this->input->post('value'); $this->load->model('Page_models'); if ($keyword == ""){ $data['tours'] = $this->Page_models->get_serach_result($keyword); } else{ $data['tours'] = $this->Page_models->get_turs(); } $this->load->view('tur.php',$data); } 

Model:

 public function get_serach_result($keyword){ print_r($keyword); $array = array('blok_title' => $keyword, 'tur_name' => $keyword); $this->db->like($array); $query = $this->db->get('main_turs'); return $query->result(); 

}

It turns out there is a div. in inside diva through load the data is loaded (when the page loads). For some reason, my ajaxe does not work $ ('. Load'). Load ('tur_search'); Tell me, how can I do it better?

  • If $keyword == "" then you are looking for something on it. Maybe the opposite - you need to look for when the $keyword not empty? - u_mulder
  • .load('tur_search') loads the data returned by tur_search . Do you have such a URL? Does he give something away? - u_mulder
  • Maybe it's time to open the developer console and there is something to look at? - u_mulder
  • @u_mulder yes, it gives. - Ulan

1 answer 1

If I understand everything correctly, then you need this:

 $.ajax({ method:"POST", url:"main/tur_search", data:{value:value}, success: function(data) { $('.load').text(data); } }); 
  • does text () just output as string? but I need all the styles to be preserved as a block with a picture, they were originally so - Ulan
  • @ Ulan Master: $('.load').html(data); - Manitikyl