AJAX-запрос
$(function() {
$('#client_name').keypress(function()
{
var self = $(this);
$.post("<?php echo site_url('clients/ajax/name_query'); ?>", {
query: self.val()
}, function(data)
{
var json_response = eval('(' + data + ')');
self.data('typeahead').source = json_response;
});
});
});
PHP
public function name_query()
{
// Load the model
$this->load->model('clients/mdl_clients');
// Get the post input
$query = $this->input->post('query');
$clients = $this->mdl_clients->select('client_name, client_phone')->like('client_name', $query)->order_by('client_name')->get(array(), FALSE)->result();
$response = array();
foreach ($clients as $client)
{
$response[] = $client->client_name;
}
echo json_encode($response);
}
Движок FusionInvoice