I would like you to help me, I can not find the error, I see that you return the data, but they are not shown. I'm trying to auto-complete using bootstrap
View:
<script type="text/javascript">
$("[name=codigo]").autocomplete({
source: "<?php echo base_url() ?>index.php/articulo/getarticulos",
minLength: 3,
select: function( event, ui ) {
if (ui.item.id) {
$("[name=codigo]").val(ui.item.codigo);
return false;
}
},
search: function (event, ui ) {
$("[name=codigo]").val(0);
}
});
</script>
<div class="form-group">
<div class="col-xs-6">
<div class='input-group'>
<span class="input-group-addon"><span class="glyphicon glyphicon-tag"></span></span>
<input id="txtcodigo" name="codigo" type="text" placeholder="Codigo" value="" class="form-control" required="">
</div>
</div>
</div>
Controller:
public function getarticulos()
{
$q = trim($this->input->get('term'));
$where = array('like codigo' => $q);
$productoresult = $this->articulo_model->All($where);
$result = array();
foreach ($productoresult as $i => $articulo) {
$result[$i]['id'] = $articulo->id;
$result[$i]['codigo'] = $articulo->codigo;
$result[$i]['descripcion'] = $articulo->descripcion;
$result[$i]['precioactual'] = $articulo->precioactual;
}
echo json_encode($result);
}
Model:
The all
method inherits it from the class CI_MODEL(system->core->Model)
, which comes in the Codeigniter, I do it as it is in another project, and it works perfectly for me to auto-complete, but now I'm using bootstrap in another project and the data does not appear in the view. and I do not miss any mistakes.
class Articulo_Model extends CI_Model {
function __construct()
{
parent::__construct('articulo', NULL, 'Articulo_Model');
}
}
I hope you can help me.