Typeahead show show key和value

时间:2018-06-16 19:25:39

标签: javascript php typeahead.js

大家好请大约1周我正在尝试使用Typeahead获取密钥和值,因为我使用json_encode(array(“key”=>“value”))。但它不起作用

这是我的Javascript代码:

  $('input.typeahead').typeahead({
source: function(query, process){
  $.ajax({
    url : "http://localhost/project/tasks/getRelatedAccount",
    type : 'POST',
    data : 'query='+query,
    dataType : 'JSON',
    async : true,
    success : function(data){
      return process(data.jsonkey);
    }
  });
}
});

我的PHP代码

public function getRelatedAccount(){
        $feed = array();
        $data = $this->task->getRelatedAccount($this->input->post('query'))->result();
        foreach($data as $key => $value){
            $feed['name'] = $value->contact_name;
            $feed['id'] = $value->contact_id;
        }
        echo json_encode($feed);
    }

0 个答案:

没有答案