0

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

1
  • 1
    You really shouldn't have to include PHP in your Javascript file to get the corrent URL... surely relative URL will work here? Commented Aug 31, 2010 at 6:48

1 Answer 1

2
$(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).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.