で作業していない....jQueryのUIオートコンプリートは、私は、データベースから値を自動補完するために私のビューにフィールドを取得しようとしているが、間違っている何が起こっているかを把握することができないようCodeIgniterの
私にはビュー、私は次のスクリプトがあります:私は「提案」機能を持っている私のcontentmanagementコントローラ内
$(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();
}
上記のクエリは、「質問のWHERE質問LIKE%$ term%からのSELECT質問」と同等です。
誰にでも私がこれで間違っているのを見ることができますか?
またはものは何でも使用している開発者向けツール、 JSONレスポンスはサーバーから戻ってくるように見えますか? –
一見するとあなたはうまく見えます。いくつかのデバッグ文を追加し、Firebugのようなものを使ってリクエストを調べる必要があると思います。 – Sukumar
コードがモデルgetAutocompleteまで到達し、そこで失敗するようです - 私が得るエラーメッセージは "非オブジェクト上のメンバ関数を呼び出し"です$ term変数が得られているので問題が何も表示されませんうまくいった? –