[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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Autocomplete example</title>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
[removed][removed]
[removed][removed]
[removed]
$(document).ready(function() {
$(function() {
$( "#autocomplete" ).autocomplete({
source: function(request, response) {
$.ajax({ url: "<?php echo site_url('site/suggestions'); ?>",
data: { term: $("#autocomplete").val()},
dataType: "json",
type: "POST",
success: function(data){
response(data);
}
});
},
minLength: 2
});
});
});
[removed]
</head>
<body>
Text: <input type="text" id="autocomplete" />
</body>
</html>
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