Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript codeigniter中的自动完成搜索_Javascript_Jquery_Ajax_Codeigniter - Fatal编程技术网

Javascript codeigniter中的自动完成搜索

Javascript codeigniter中的自动完成搜索,javascript,jquery,ajax,codeigniter,Javascript,Jquery,Ajax,Codeigniter,Hy,我正在codeigniter中做一个自动完成搜索字段 以下是我的看法: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery

Hy,我正在codeigniter中做一个自动完成搜索字段

以下是我的看法:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<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>
$(document).ready(function() {
    $(function(){
        $( "#text" ).autocomplete({
            source: function(request, response) {
                $.ajax({
                url: "http://localhost/new/index.php/travels/search_fields",
                data: { term: $("#text").val()},
                dataType: "json",
                type: "POST",
                success: function(data){
                    response(data);
                }
            });
        },
        minLength: 2
        });
    });
});
</script>
</head>

<body>
<form method="post">
 <input type="text" name="text" id="text" autocomplete="off" > 
</form>
</body>
</html>
这是我的模型:

 function search_field($term){
    $this->db->distinct();
    $this->db->select("destination");
    $this->db->from('travels_detail');
    $this->db->like('destination', $term);
     $this->db->group_by('travels_detail.destination');
    $query = $this->db->get();
    return $query->result();

}

我得到一个空的下拉列表,我哪里做错了??ajax或库等有什么问题吗?请任何人帮助我

在模型返回
结果\u数组中

return $query->result_array();
在控制器中:

$search_data = $this->Travel->search_field($term); 
echo json_encode($search_data);
ajax成功后的一些变化:

success: function(data){
   var resp = $.map(data,function(obj){
        return obj.destination;
   }); 
   response(resp);
}

在模型返回
结果\u数组中

return $query->result_array();
在控制器中:

$search_data = $this->Travel->search_field($term); 
echo json_encode($search_data);
ajax成功后的一些变化:

success: function(data){
   var resp = $.map(data,function(obj){
        return obj.destination;
   }); 
   response(resp);
}

响应前(数据)行使用
console.log(数据)
并显示。在
响应(数据)之前让我知道行使用
console.log(数据)
并显示。让我知道Thanx@razib al-mamunthanx@razib al-mamun