I'm filling a table in php using axios.get that I send to an api to collect data from the database, the problem is that, in the response.data is not returning an object, if not an array, which does not work to fill my table
Correct example
function eventoBotonBuscar(){
var campoValor = document.getElementById("valor");
axios.get("http://tiamex.ddns.net/sitios/upemor/apiRestPHP/restUsuario.php/findByName/"+campoValor.value)
//axios.get("http://localhost/sitios/upemor/webService/apiRestPHP/restUsuario.php/findByName/"+campoValor.value)
.then(function (response){
var tabla = document.getElementById("tabla");
var contadorFila = tabla.rows.length;
for(var x=contadorFila-1;x>0;x--){
tabla.deleteRow(x);
}
var elementos = response.data;
var llave,fila=0,celda;
for(llave in elementos){
if(elementos.hasOwnProperty(llave)){
var filaTabla = tabla.insertRow(fila+1);
celda = filaTabla.insertCell(0).innerHTML = elementos[fila].id;
filaTabla.insertCell(1).innerHTML = elementos[fila].nombre;
filaTabla.insertCell(2).innerHTML = elementos[fila].correo;
filaTabla.insertCell(3).innerHTML = elementos[fila].edad;
filaTabla.insertCell(4).innerHTML =
"<button type=\"button\" class=\"btn btn-danger btn-rounded btn-sm my-0\"onclick=\"eventoBotonEliminar("+elementos[fila].id+")\" /><i class=\"glyphicon glyphicon-remove\"></i></button>"+
"<button type=\"button\" class=\"btn btn-success btn-rounded btn-sm my-0\"onclick=\"eventoBotonEditar("+elementos[fila].id+")\" /><i class=\"glyphicon glyphicon-edit\"></i></button>";
fila++;
}
}
})
.catch(function (error){
document.write("<h1>Error al procesar la solicitud: "+error+"</h1>");
});
}
This is shown in the development
And this is the code of my table to fill that appears to me as undefined
function eventoBotonBuscar(){
var campoValor = document.getElementById("valor");
//axios.get("http://tiamex.ddns.net/sitios/upemor/apiRestPHP/restUsuario.php/findByName/"+campoValor.value)
axios.get("http://localhost/pruebahotel/RestCliente.php/findByName/"+campoValor.value)
.then(function (response){
var tabla = document.getElementById("tabla");
var contadorFila = tabla.rows.length;
for(var x=contadorFila-1;x>0;x--){
tabla.deleteRow(x);
}
var elementos = response.data;
//document.write(response.data);
var llave,fila=0,celda;
for(llave in elementos){
if(elementos.hasOwnProperty(llave)){
var filaTabla = tabla.insertRow(fila+1);
celda = filaTabla.insertCell(0).innerHTML = elementos[fila].idcliente;
filaTabla.insertCell(1).innerHTML = elementos[fila].nombre_cliente;
filaTabla.insertCell(2).innerHTML = elementos[fila].cargo;
filaTabla.insertCell(3).innerHTML = elementos[fila].departamento;
/*filaTabla.insertCell(4).innerHTML = elementos[fila].direccion_principal;
filaTabla.insertCell(5).innerHTML = elementos[fila].correo_electronico;
filaTabla.insertCell(6).innerHTML = elementos[fila].descripcion;
filaTabla.insertCell(7).innerHTML = elementos[fila].telefono_oficina;
filaTabla.insertCell(8).innerHTML = elementos[fila].telefono_movil;
filaTabla.insertCell(9).innerHTML = elementos[fila].fax;
filaTabla.insertCell(10).innerHTML = elementos[fila].direccion_alternativa;
filaTabla.insertCell(11).innerHTML = elementos[fila].fecha_creacion;*/
filaTabla.insertCell(4).innerHTML =
"<button type=\"button\" class=\"btn btn-danger btn-rounded btn-sm my-0\"onclick=\"eventoBotonEliminar("+elementos[fila].idcliente+")\" /><i class=\"glyphicon glyphicon-remove\"></i></button>"+
"<button type=\"button\" class=\"btn btn-success btn-rounded btn-sm my-0\"onclick=\"eventoBotonEditar("+elementos[fila].idcliente+")\" /><i class=\"glyphicon glyphicon-edit\"></i></button>";
fila++;
}
}
})
.catch(function (error){
document.write("<h1>Error al procesar la solicitud: "+error+"</h1>");
});
}
It shows that returns an array and not an object
How do I return the response.data as an object ??