0

jQuery UI と CodeIgniter 2 を使用して単純なオートコンプリート スクリプトを実装しようとしていますが、モデルが未定義の変数があることを伝え続けるため、セットアップが正しいかどうかわかりません。

私の見解

$(function() {
   $("#txtUserSuburb").autocomplete({
      source: function(request, response){
         $.ajax({ 
            url: "autocomplete/suggestions",
            data: { 
               term: $("#txtUserSuburb").val()
            },
            dataType: "json",
            type: "POST",
            success: function(data){
               response(data);
            }
         });
      },
      minLength: 2
   });
});

私のコントローラー

function suggestions(){
   $this->load->model('autocomplete_model');
   $term = $this->input->post('term', TRUE);
   $rows = $this->autocomplete_model->getAutocomplete($term);
   echo json_encode($rows);
}

私のモデル

function getAutocomplete() {
   $this->db->like('postcode', $term, 'after'); 
   $query = $this->db->get('tbl_postcode');
   $keywords = array();
   foreach($query->result() as $row){
      array_push($keywords, $row->postcode);
   }        
   return $keywords;
}

$term 変数をモデルに渡していないように見えることを除いて、エラーはありません。

4

2 に答える 2

3

ええ、パラメータ "$term" を持つには getAutocomplete() が必要だと思います:

function getAutocomplete($term) {
于 2012-05-02T22:13:31.167 に答える