开发者

how to send data to Codeigniter controller in jquery ajax?

开发者 https://www.devze.com 2023-01-14 11:37 出处:网络
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 e

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开发者_如何学Go(){
   $('#search').live('click',function(eve){
    eve.preventDefault();
    $.get('<?php echo base_url();?>index.php/search_controller/perform', function(data) {
        $('#result').html(data);
    });     
   });
   });

regards, Rangana


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

0

精彩评论

暂无评论...
验证码 换一张
取 消