【发布时间】:2018-06-20 06:57:39
【问题描述】:
我正在使用 CodeIgniter。我正在使用有效的 ajax 创建实时自动完成 textbox。我签入了网络选项卡,还在成功的 ajax 中添加了警报。我得到了正确的输出。
现在,当用户输入文本时,如何在文本框中显示列表?我应该使用 Json 以及如何使用?
当用户在文本框中输入任何字母时,我必须显示名称列表。
你能帮我解决这个问题吗?
我的观点
<input type="text" name="cust_name" placeholder="Enter the name" class="form-control" id="title">
Ajax
$(document).ready(function(){
$('#title').autocomplete({
source: baseUrl + "/Search/get_search_record",
select: function (event, ui) {
$('#title').val(ui.item.label);
}
});
});
控制器
public function get_search_record(){
if (isset($_GET['term'])) {
$result=$this->Search_model->search_cust_name($_GET['term']);
if (count($result) > 0) {
foreach ($result as $row)
$arr_result[] = array(
'first_name' => $row->first_name,
'last_name' => $row->last_name,
);
echo json_encode($arr_result);
}
}
}
型号
public function search_cust_name($emp_name){
$this->db->like('first_name', $emp_name , 'both');
return $this->db->get('members')->result();
}
我正在网络选项卡中获取输出
[{"first_name":"Naren","last_name":"Verma"}]
【问题讨论】:
-
要么将结果编码并返回为 json,然后在 javascript 中构建 html,要么在 php 中构建您需要的 html 并返回。
-
您希望在哪里显示您的数据?您希望它显示在表格、文本字段还是输入框中?
-
我有一个输入框,我必须在里面显示。谷歌之类的东西。
-
@pradeep,我检查了jqueryui,但是如何在其中显示数据表单数据库?
标签: php jquery ajax codeigniter jquery-ui-autocomplete