skip to Main Content

this is my js code which is executed on button click

    $("#search_tutor").click(function(){
    $("#show_tutors").hide();
    var subject = $( ".subject" ).val();
    var degree_level = $(".degree_level").val();
    var city = $(".city").val();
    console.log(subject);
    console.log(degree_level);
    console.log(city);
      $.ajax({
      url:"<?php echo base_url(); ?>public_controller/search_tutor_jquery",
      method:"post",
      data:{subject: subject, degree_level : degree_level, city : city},
      success:function(data){
        $('#search_results').html(data);

      }
    });

    });

and this is controller function

        public function search_tutor_jquery(){
  $subject = strtolower($this->input->post('subject'));
  $degree_level = strtolower($this->input->post('degree_level'));
  $city = strtolower($this->input->post('city'));
  echo $subject; //prints nothing
  $data['filtered_tutors'] = $this->public_model->search($subject,$degree_level,$city);
  $this->load->view('public/search_results',$data);
}

values are being logged in console but i cannot receive values in controller. can somebody help me out?
thanks in advance

2

Answers


  1. Have you tried using

    $_POST['subject']
    

    instead of

    $this->input->post('subject')
    

    ?

    Login or Signup to reply.
  2. What do you mean by

    $('#search_results').load("<?php echo base_url('public_controller/search_tutor_jquery') ?>");
    

    Try

    $('#search_results').html(data);
    

    Read about load() function here. It sends a new empty request and load that data to your element. It doesn’t load the response.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search