3
我的項目中存在一些問題。我正在嘗試在CodeIgniter中使用JavaScript進行自動完成。我已經嘗試了很多選擇,但他們不工作!數據庫Codeigniter Autocomplete
控制器:
public function getResult($referencia){
if(!empty($referencia) || isset($referencia))
{
$this->db->like('referencia', $referencia);
echo json_encode($this->db->get('produto_servico_tbl')->result());
}
}
的autocomplete.js(我創建):
$(document).ready(function(){
$('#search').keypress(function(e){
if(e.which == 13)
{
e.preventDefault();
}
var searched = $('#search').val()
var fullurl = $('#hiddenurl').val() + 'autoComplete_v.php/autoComplete_c/getResult/' + searched
$.getJSON(fullurl,function(result){
//display suggestion code goes here
var elements = [];
$.each(result, function(i, val){
elements.push(val.referencia)
})
$('#search').autocomplete({
source : elements
})
})
})
})
的視圖:
<head>
<link href="<?=base_url()?>css/ui-lightness/jquery-ui-1.10.3.custom.css" media="screen" type="text/stylesheet" rel="stylesheet" />
<form>
<label for="search">Search</label>
<input id="search" type="text"/>
<input value="<?=base_url()?>" id="hiddenurl" type="hidden">
<input type="submit" value="submit"/>
</form>
<script src="<?=base_url()?>js/jquery-1.9.1.js" type="text/javascript"></script>
<script src="<?=base_url()?>js/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>
<script src="<?=base_url()?>js/jquery-ui-1.10.3.custom" type="text/javascript"></script>
<script src="<?=base_url()?>js/autocomplete.js" type="text/javascript"></script>
非常感謝!現在我有bootstrap css的問題,但我會嘗試解決它們!謝謝 – CesarMiguel