good to all, again, JSON em is something Troll because it is easy to deal with the data in this way but I do not understand in this case the reason why it does not work, I have this JavaScript code (not yet complete)
function ver_bookmark(id_sub_categoria){
console.log(id_sub_categoria);
if( $("#add").length > 0 ) {
$.post('.show_bookmarks.php',{id_sub_categoria:id_sub_categoria},
function(response){
response = JSON.parse(response);
console.log(response);
for(var i in response){
//hago un console.log(response[i]) y lo hace
//bien pero cuando le aññado en este caso que me muestre el id o algun otro dato
// es donde falla
console.log(response[i].id);
$('#add').html(
$('<div/>',{'id':'my_card','class':'col s12 m6'}).append(
$('<div/>',{'class':'card'}).append(
$('<div/>',{'class':'card-image'}).append(
$('<img/>',{'src':'ficheros/bookmark/'+response[i].fichero})
)
)));
}
});
}else{
console.log("no existe");
}
}
the data in the PHP file is here
$lista_bookmark =lista_bookmark('',$conn);
$lista_book = [];
for ($i=0; $i < $lista_bookmark['count']; $i++) {
if ($_POST['id_sub_categoria'] == $lista_bookmark[$i]['id_book_subcategoria']) {
$lista_book = array(
'id' => $lista_bookmark[$i]['id'],
'id_book_subcategoria'=> $lista_bookmark[$i]['id_book_subcategoria'],
'url'=> $lista_bookmark[$i]['url'],
'titulo' => $lista_bookmark[$i]['titulo'],
'usuario' => $lista_bookmark[$i]['usuario'],
'password' => $lista_bookmark[$i]['password'],
'notas' => $lista_bookmark[$i]['notas'],
'fichero' => $lista_bookmark[$i]['fichero'],
'favorito' => $lista_bookmark[$i]['favorito']);
}
}
echo json_encode($lista_book, JSON_FORCE_OBJECT);
in the javaScript code when I put it to show what it collects from the file .PHP does it well, I do console.log(respose)
when it is already in JSON format and it does it well, would someone know what my error is ?, it is not the first time I work with this, in fact I already have several doubts resolved in this medium, fixed that it will be some nonsense and I'm sorry but I do not see it because when I have it printed to me response[i]<cualquier parametro>
appears as undefined.
a greeting.
and thanks for the attention :) I leave images of what shows exactly.