我試圖讓我的視野從數據庫值自動完成,但似乎無法找出什麼錯誤的工作....jQuery UI的自動完成功能不是笨
在我鑑於我有以下腳本:
$(document).ready(function() {
$(function() {
$("#searchQuestion").autocomplete({
source: function(request, response) {
$.ajax({ url: "<?php echo site_url('contentmanagement/suggestions'); ?>",
data: { term: $("#searchQuestion").val()},
dataType: "json",
type: "POST",
success: function(data){
response(data);
}
});
},
minLength: 2
});
});
});
在我的內容管理控制器我有「建議」功能:
function suggestions() {
$this->load->model('onlinehelp');
$term = $this->input->post('term', TRUE);
if (strlen($term) < 2)
break;
$rows = $this->onlinehelp->GetAutocomplete($term);
$keywords = array();
foreach ($rows as $row)
array_push($keywords, $row->question);
echo json_encode($keywords);}
,最後我的模型中我有如下功能 -
function GetAutocomplete($term) {
$this->db->select('question');
$this->db->like('question',$term, 'both');
$query = $this->db->get('question');
return $query->result();
}
以上查詢是等同於「FROM選擇有問題的問題在那裏同樣%$長期%的問題。
任何人都可以看到我要去哪裏錯了?
在Firebug的,或者你使用任何開發工具, JSON響應看起來像從服務器回來什麼? –
你乍一看似乎很好。我想你需要添加一些調試語句,並使用諸如Firebug之類的東西來查看請求。 – Sukumar
該代碼似乎得到儘可能的模型getAutocomplete,並在那裏失敗 - 我得到的錯誤消息是「調用一個非對象的成員函數」我不明白是什麼問題,因爲$ term變量越來越通過罰款? –