[eluser]Shiju S S[/eluser]
I have the script as
Code:
$(function()
{ $( "#tags" ).autocomplete({
source: function(req, add){
var fields = $("#tags").val(); //Get input
$.ajax({
url: '<?php echo base_url('frontpage/autocomplete');?>',
dataType: 'json',
type: 'POST',
data: fields,
success: function(data){
add(data);
}
});},
minLength: 0,
select: function( event, ui )
{
log( ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value );
}
});
});
The input is:
Code:
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags" name="name">
</div>
I have the controller frontpage with autocomplete mehod
Code:
public function autocomplete()
{
$searchterm = $this->input->post('fields');
$query ="SELECT DISTINCT category FROM listeditems WHERE MATCH (category,subcategory,title,details,address) AGAINST ('$searchterm') > 0";
$result = $this->sales_exe_details_db->get_results($query);
if($result)
{ $i=0;
foreach($result as $row):
$data[] = array('id' => $i, 'label' => 'group', 'value'=> $row->category);
$i++;
endforeach;
}
echo json_encode($data);
}
I am not getting any value in the $searchitem. Please help