0
I am having a problem with Ajax... I am not able to extract the data. They are returned, however, at the time of printing, nothing appears.
Follows codes:
Model:
function livros() {
$this->db->select('idobras,titulo,idbib_exemplares,bib_obras_idobras');
$this->db->from('bib_exemplares');
$this->db->join('bib_obras', 'idobras = bib_obras_idobras');
$this->db->where('estado','Ativo');
$this->db->order_by('titulo','asc');
$result = $this->db->get();
if ($result->num_rows() > 0) {
return $result->result();
} else {
return false;
}
}
Controller:
function GetLivros() {
$book = $this->bib_movimentacao_model->livros();
if ($book) {
echo json_encode($book);
}else{
echo json_encode('');
}
}
Excerpt from the Jquery:
print = '<div id="rem">'+
'<blockquote>'+
'<div class="form-inline">'+
'<label>Livro: </label>';
$.ajax({
'url': 'bib_movimentacao_controller/GetLivros',
'type': 'POST',
'data': {
},
'success': function(data){
var result = JSON.parse(data);
alert(data);
print += '<select name="livros[]" id="livros" class="form-control" data-live-search="true" style="width: 80%">';
$.each(result, function(index, val){
print += '<option value="'+val.idbib_exemplares+'">'+val.titulo+'</option>';
});
print += '</select>';
}
});
print += '</div>'+
On that Alert, I saw that the data is being brought in correctly.
Thanks for the help, guys.
P.S.: Follows image of how it looks:
Thank you so much for your help, Gabriel! It worked!! Ooo/
– Deh TR