【发布时间】:2018-01-18 11:18:46
【问题描述】:
嗨,我正在 codeigniter 中创建一个自动完成搜索字段,我尝试使用以下代码在 codeignter 中进行自动完成。但它对我不起作用。在自动完成文本字段中不显示任何内容。任何人都可以找到问题
数据显示为未定义的成功函数
这是我的看法:
View
<script >
$(document).ready(function() {
$("#trackerid").change(function(){
var var_locoid= $("#trackerid option:selected").val();
alert(var_locoid);
$( "#deliverylocation" ).autocomplete({
source: function(request, response) {
var auto_data= $("#deliverylocation").val();
alert(auto_data);
//alert(var_locoid);
$.ajax({
url:"http://localhost/testcontroller/test/lookup",
type:"POST",
datatype:'json',
data:{'var_locoid' :var_locoid,'auto_data':auto_data},
success: function(data){
response(data);
alert(data);
}
});
},
minLength: 1
});
});});
</script>
<input type="text" name="deliverylocation" id="deliverylocation" placeholder="Enter your area " >
控制器
function lookup()
{
$citys = $this->input->post('var_locoid');
$auto_text = $this->input->post('auto_data');
//var_dump($citys);
//$data['response'] = 'false';
$place = $this->Demo_model->load_places($citys,array('keyword' => $auto_text));
$json_array = array();
foreach ($place as $row){
array_push($json_array, $row->locationtext);
}
//echo json_encode($place);
echo json_encode($json_array);
}
Model
function load_places($citys,$auto_text)
{
//$this->db->select('locationtext');
$this->db->select('locationtext');
$this->db->like('locationtext', $auto_text);
$this->db->from('tbl_location');
$array = array('cityautocode' => $citys);
$this->db->where($array);
//$this->db->->where('cityautcode', $place);
$query= $this->db->get();
//echo $this->db->last_query();
return $query->result();
}
【问题讨论】:
标签: javascript jquery codeigniter autocomplete