自动完成codeigniter问题

时间:2015-08-11 17:59:18

标签: codeigniter autocomplete

我想问一下问题,当我输入关键字时,为什么自动完成功能会改变动态?它只显示所有数据。 ----控制器------

function control_areas(){
$term = $this->input->get('term', TRUE);
$brands = $this->dashboard_model->get_areas($term);
echo json_encode($brands);
}

----模型----

function get_areas($term){
$this->db->like('brand_name', $term, 'after');
$query = $this->db->get('tbl_brand');
return $query->result(); 
}

----脚本-----

$(function(){
var $sfield = $('‪#‎autocomplete‬').autocomplete({
source: function(request, response){
var url = "<?php echo site_url('dashboard/control_areas'); ?>";
$.post(url, {data:request.term}, function(data){
response($.map(data, function(brands) {
return {
value: brands.brand_name
};
}));
}, "json"); 
},
minLength: 2,
autofocus: true
});

----查看-----

<input type="text" id="autocomplete" name="brand-name" placeholder="Enter text here" class="full text"/>

0 个答案:

没有答案