打字它只是逐字母回复

时间:2017-04-10 22:38:16

标签: codeigniter-3 bootstrap-typeahead jquery-ajaxq

我想制作一个自动填充搜索框,当我尝试实现搜索时,它会逐字逐句地返回我,而不是逐字逐句地返回。当我有两个值时,它也会从db返回一个值。我正在使用bootstrap中的typeahead.min.js。为什么会这样?

控制器

public function search(){
        $search = $this->input->post('search');
        $query  = $this->products->search($search);
        $data = array();
        foreach ($query as $key => $value) {
           $this->json($value);
        }
    }

模型

public function search($data){
        $this->db->like('description',$data,'both');
        $query = $this->db->get('storelte_products');
        return $query->result_array();
    }

AJAX

    $('#search').typeahead({
      source: function (query,process) {
        $.ajax({
            url: URL_SEARCH_PRODUCT,
            type: 'POST',
            data: {query: query},
            dataType: 'json',
            async: true,
            success: function (data) {
              console.log(data);
              process(data.description);
            }
        });
      }
   });

search_box 杰森

{"id":"4165","provider_id":"1005","hash_id":"a7f0d2b95c60161b3f3c82f764b1d1c9","code":"BCBF-BE6A","description":"ajg","purchase_price":"7.00","sale_price":"77.00","wholesale_price":"7.00","min_stock":"7","stock":"7","max_stock":"7","created_at":"2017-04-09 22:21:28","status":"1"}

table_Db

0 个答案:

没有答案