0

私は最近、CIを手に入れ、まだ学習しています。DBから仕事にCIオートコンプリートを受け取ることができません

マイコントローラ:

public function test() { 
    $keyword=$this->input->post('search[1]'); 
    $data=$this->hbc_model->search_autocomplete($keyword);   
    //echo json_encode($data); 

    $this->load->view('headfoot/test-header-main'); 
    $this->load->view('test'); 
    $this->load->view('headfoot/test-footer-main'); 
} 

モデル:

function search_autocomplete($search_term){ 
    $this->db->select('v_city_name'); 
    $this->db->like('v_city_name', $search_term); 
    $response = $this->db->get('vbc_city')->result_array(); 
    // var_dump($response); 
    return $response; 
} 

とビュー:

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" /> 
<script src="http://code.jquery.com/jquery-1.8.3.js"></script> 
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
    $("#main-search").autocomplete({ 
    source: 'hbc_Model/search_autocomplete' 
    }); 
    }); 
</script> 
</head> 
<body> 
<input type="text" id="main-search" name="search[1]" size="20" /> 
</body> 

私はモデルやコントローラからでもエコーJSONレスポンスからvardumpのコメントを解除すると、それは都市を表示データベースからページ全体に名前を付けるが、オートコンプリートとして使用すると機能しない。

ご協力いただければ幸いです。

+1

'.autocomplete()'関数はjQueryUIの一部であるので、私はあなたの質問に、これらのタグを追加しました。あなたの問題はおそらくJavaScriptなので、ブラウザコンソールでエラーを探す必要があります。 – Sparky

答えて

1

オートコンプリートがproper formattedソースデータを期待: 私はそのように進行する:

$response = $this->db->get('vbc_city')->result_array(); 
$outputString=""; 
foreach ($response as $city) 
$outputString.="'".$city['v_city_name']."',"; 

print "[".substr(SoutputString,0,-1)."]"; 
die; // or else the page html will be printed too! 
関連する問題