php - calling controller function from view and retrieving rows from db using AJAX in codeigniter -
i trying retrieve rows database making ajax call controller function. have no error messages , code executing upto $("#msgbox").html("type name of or something...");
i think controller not called view. below mvc code.
my view: welcome_message.php
<div id="centersearch"> <script type="text/javascript" src="http://ajax.googleapis.com/ ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { var start=/^((?!part).)*$/ var word=/^((?!part).)*$/ $("#contentbox").live("keyup",function() { var content=$(this).text(); //content box data var go= content.match(start); //content matching @ var name= content.match(word); //content matching @abc var datastring = 'searchword='+ name; //if @ available if(go.length>0) { $("#msgbox").slidedown('show'); $("#display").slideup('show'); $("#msgbox").html("type name of or something..."); //if @abc avalable if(name.length>0) { $.ajax({ type: "post", url: "<?php $this->load->helper('url'); echo base_url();?>index.php/welcome/ ?>", // database name search data: datastring, cache: false, success: function(data) { $("#msgbox").hide(); $("#display").html(data).show(); } }); } } return false(); }); //adding result name content box. $(".addname").live("click",function() { var username=$(this).attr('title'); var old=$("#contentbox").html(); var content=old.replace(word," "); //replacing @abc (" ") space $("#contentbox").html(content); var e="<a class='red' contenteditable='false' href='#' >"+username+"</a>"; $("#contentbox").append(e); $("#display").hide(); $("#msgbox").hide(); }); }); </script>
my controller: welcome.php
public function search() { $this->load->database(); //load model $this->load->model('select'); //load method of model $data['s']=$this->select->search(); $this->load->view('welcome_message', $data); }
my model: select.php
public function search($datastring) { $query = $this->db->select('*') ->from('country') ->where('from', $datastring) ->get(); return $query; }
you can call helper in constructor
function __construct() { parent::__construct(); $this->load->helper('url'); }
and ajax url is
url: "<?php echo base_url();?>index.php/welcome/search?>",
Comments
Post a Comment