【发布时间】:2016-12-22 00:24:42
【问题描述】:
我的搜索表单中有一个下拉字段,但问题是我收到一条消息:(17 个结果可用,使用向上和向下箭头键导航。)在输入字段而不是结果下。
我的代码是:
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" ></script>
<script type="text/javascript">
$(document).ready(function() {
$(function(){
$( "#destination" ).autocomplete({
source: function(request, response) {
$.ajax({
url: "http://localhost/fantastic/Travels/search_fields",
data: { term: $("#destination").val()},
dataType: "json",
type: "POST",
success: function(data){
var resp = $.map(data,function(obj){
return obj.destination;
});
response(resp);
}
});
},
minLength: 1
});
});
});
</script>
我的控制器代码是:
function search_fields(){
$term = $this->input->post('term', TRUE);
$search_data = $this->Travel->search_field($term);
echo json_encode($search_data);
}
我的型号代码是:
function search_field($term){
$query = $this->db->query("SELECT distinct(destination) FROM travels_detail WHERE destination LIKE '".$term."%' group by destination");
return $query->result_array();
}
我将相同的代码应用到另一个站点并且它正在工作。但在另一个网站上,它给我消息“有 17 个结果可用,请使用向上和向下箭头键导航。”这 17 个结果显示在 keyup 和 keydown 按钮上。
有人知道吗??请告诉我
【问题讨论】:
标签: php jquery ajax codeigniter