我看到很多方法可以进行打字,但仍然无法与我合作。我弄错了吗? 这是我的代码。
view:personal.php
<script>
$(function() {
$('#search').typeahead({
source: function(typeahead, query) {
$.ajax({
url: "messages/search_name",
type: "post",
data: "search=" + query,
dataType: "json",
async: false,
success: function(data) {
typeahead.process(data);
}
});
}
});
});
</script>
<input type="text" name="search" id="search" class="typeahead">
controller:messages
public function search_name()
{
$data = $this->mysms_model->search_name_person();
echo json_encode($data);
}
model:mysms_model
public function search_name_person()
{
$office = $this->input->post('search');
$this->db->select('name');
$this->db->from('contacts');
$this->db->like('name', $office);
$query = $this->db->get();
$office_array = array();
foreach ($query->result() as $row) {
$office_array[] = $row->name;
}
$data['office'] = $office_array;
return $data;
}
我的表名是联系人(cid,name)。 谢谢你的帮助。