我的项目有一些问题。我正在尝试在 CodeIgniter 中使用 JavaScript 进行自动完成。我已经尝试了很多选择,但它们不起作用!
控制器:
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>