[eluser]goldensona[/eluser]
hi thanks a lot to you pickupman. i used you controller file , now no error shows but autocomplete didnt populate i dont know why ? is anything we have to changed in the autocomplete.js file?
we used post for getting the autocomplete response , i cant see the difference .
this is whole code after i changed the controller file
changed the config.php
Code:
//Global define for AJAX Requests
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
js part search.php
Code:
< cript t ype="text/javascript" src="<?php echo base_url()."jquery-ui-1.8.4.custom/development-bundle/jquery-1.4.2.js"?>">[removed]
< cript t ype="text/javascript" src="<?php echo base_url()."jquery-ui-1.8.4.custom/development-bundle/ui/jquery.ui.core.js"?>">[removed]
< cript t ype="text/javascript" src="<?php echo base_url()."jquery-ui-1.8.4.custom/development-bundle/ui/jquery.ui.widget.js"?>">[removed]
< cript t ype="text/javascript" src="<?php echo base_url()."jquery-ui-1.8.4.custom/development-bundle/ui/jquery.ui.position.js"?>">[removed]
< cript type="text/javascript" src="<?php echo base_url()."jquery-ui-1.8.4.custom/development-bundle/ui/jquery.ui.autocomplete.js"?>">[removed]
[removed]
//Javascript
$("input[name='singlecity']").autocomplete({
source: function(req, add){
$.ajax({
url: '<?php echo site_url('searchs');?>',
dataType: 'json',
type: 'POST',
data: req,
success: function(data){
if(data.response =='true'){
add(data.message);
}
}
});
},
minLength: 3,
select: function(event, ui){
$(this).end().val(ui.item.value);
}
});
[removed]
</head>
<body>
<input type="text" name="singlecity" size="48">
</body>
my model file searchcity.php
Code:
<?php
class Searchcity extends Model {
function Searchcity() {
// load the parent constructor
parent::Model();
}
function citysearch($search)
{
if(empty($part_number)) return FALSE; //nothing to search
$this->db->like('city', $search);
$query = $this->db->get('tablenames');
if($query->num_rows() > 0)
return $query->result();
return FALSE;
}
}
?>
this is my searchs.php controller file
Code:
<?php
class Searchs extends Controller{
function Searchs(){
// load Controller constructor
parent::Controller();
// load the model we will be using
$this->load->model('searchcity');
// load the database and connect to MySQL
$this->load->database();
// load the needed helpers
$this->load->helper('url');
}
function index(){
$search = $this->input->get('term');
$data['response'] = 'false';
$result = $this->searchcity->citysearch($search); //Search DB
if($result != FALSE)
{
$data['response'] = 'true'; //Set response
$data['message'] = array(); //Create array
foreach($result as $row)
{
$data['message'][] = array('label'=> $row->id, 'value'=> $row->city); //Add a row to array
}
}
if(IS_AJAX)
{
echo json_encode($data); //echo json string if ajax request
}else{
$this->load->view('search',$data); //Load html view of search results
}
}
}
?>
what i have to change in my code
thanks
sona