Welcome Guest, Not a member yet? Register   Sign In
Autocomplete - jquery and codeigniter - does not work
#1

[eluser]konradinho[/eluser]
I tried to do auto-completion using codeigniter and jquery but somehow it does not work. So please help.

View:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Autocomplete example&lt;/title&gt;
&lt;link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/&gt;
[removed][removed]
[removed][removed]
[removed]
$(document).ready(function() {
$(function() {
  $( "#autocomplete" ).autocomplete({
   source: function(request, response) {
    $.ajax({ url: "&lt;?php echo site_url('site/suggestions'); ?&gt;",
    data: { term: $("#autocomplete").val()},
    dataType: "json",
    type: "POST",
    success: function(data){
     response(data);
    }
   });
  },
  minLength: 2
  });
});
});
[removed]
&lt;/head&gt;
&lt;body&gt;
Text: &lt;input type="text" id="autocomplete" /&gt;
&lt;/body&gt;
&lt;/html&gt;

Controller:

Code:
function suggestions()
{
        
              $this->load->view('autocomplete');
$this->load->model('data_model');
$term = $this->input->post('term');

$this->db->select('login');
$this->db->like('login', $term);
$query = $this->db->get('uzytkownicy');

$podpowiedzi = array();
foreach ($query->result() as $row)
      array_push($podpowiedzi, $row->login);

// Return data
echo json_encode($podpowiedzi);
}

Model:

Code:
function GetAutocomplete($options = array())
    {
     $this->db->select('login');
     $this->db->like('login', $options['login']);
        $query = $this->db->get('uzytkownicy');
  return $query->result();
    }

As a result of getting something like this:

http://img135.imageshack.us/img135/8020/...oardeb.png
#2

[eluser]Mr-H[/eluser]
hi
try this
http://vortexdev.netii.net/article_16/Ho...and_jQuery




Theme © iAndrew 2016 - Forum software by © MyBB