4
我的AJAX 自動完成做從服務器,但返回國家它始終顯示所有國家不管我型。將request.term發送給Model的控制器有問題,但我無法弄清楚它是什麼。非常感謝任何提示!jQuery的Ajax的自動完成功能與笨「術語」問題
HTML:
<input type='text' name='location_search' id='location_search' placeholder='Type Location' >
JS:
$(function(){
var $sfield = $('#location_search').autocomplete({
source: function(request, response){
var url = "<?php echo site_url('autocomplete/control_areas'); ?>";
$.post(url, {data:request.term}, function(data){
response($.map(data, function(countries) {
return {
value: countries.name_en
};
}));
}, "json");
},
minLength: 2,
autofocus: true
});
});
控制器:
function control_areas(){
$this->load->model('autocomplete_model');
$term = $this->input->get('term', TRUE);
$countries = $this->autocomplete_model->get_areas($term);
echo json_encode($countries);
}
模型:
function get_areas($term){
$this->db->where('name_en', $term);
$query = $this->db->get('countries');
return $query->result();
}
弄來了'$長期的預期值= $ this-> input-> get('term',TRUE);'? – anvoz