views:

36

answers:

1

Hi Guys,

I'm doing a search using CI and Jquery, well i'm very novice to this, this is my first time, i have done this code but i can't figure out how to send data to the controller and search for a value entered in the text box? can you guys help me to figure this out?

here is my code

$(document).ready(function(){
   $('#search').live('click',function(eve){
    eve.preventDefault();
    $.get('<?php echo base_url();?>index.php/search_controller/perform', function(data) {
        $('#result').html(data);
    });     
   });
   });

regards, Rangana

+2  A: 
$(document).ready(function(){
  $('#search').live('click',function(eve){
    eve.preventDefault();
    $.get('/index.php/search_controller/perform/' + $("#your-textbox-id").val(),    
      function(data) {
        $('#result').html(data);
      }
    );     
  });
});

Adding the textbox value to the url should work. Also, I have removed the php code for adding the baseurl. Codeigniter will take care of adding that for you.

You will have to add an argument to the perform function of your search_controller to pickup the textbox value being passed, or you can use the routing methods to get the parameter in the url (more info over here).

ShiVik
thank you very much ShiVik it was very helpful! :)
ranganaMIT