• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Short look why, please: JQuery UI autocomplete from database

#3
[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>
            &lt;input id="tags" name="name"&gt;
        </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);
    }

Nothing happens! Please help.


Messages In This Thread
Short look why, please: JQuery UI autocomplete from database - by El Forum - 02-22-2012, 12:33 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.