I have a RESTful service which stores data through a JQuery that sends a json to a POST method that inserts the object into the database.
I also have a method that reads the records from the base, and stores them in an arrayList of objects, which I should be able to list in an html table using jQuery.
How can I show that data in the html table?
Service read:
@GET
@Path("leer")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public ArrayList<Fabricante> leer() {
Respuesta r = new Respuesta();
ArrayList<Fabricante> aux = new ArrayList<>();
OperImpFab oper= new OperImpFab();
aux = oper.leer();
return aux;
}
Function check JQuery: (I tried to make that table but it does not take any value to me)
function consultar() {
var direccion = "http://localhost:8084/MarcasCarros/app/operaciones/leer";
$.ajax({
url: direccion,
type: 'GET',
async: true,
contentType: "application/json",
success: function (r) {
var lista = [];
lista = r;
var table = $('#myTable');
var row, cell;
for (var i = 0; i < lista.length; i++) {
row = $('<tr />');
table.append(row);
for (var j = 0; j < lista[i].length; j++) {
cell = $('<td>' + lista[i][j] + '</td>')
row.append(cell);
}
}
},
error: function () {
alert("Error en consultar.");
}
});
Testing the service read through the client Restlet brings me the following:
[
{
"nombre": "Renault",
"pais": "francia",
"sede": "rojo"
},
{
"nombre": "Chevrolet",
"pais": "usa",
"sede": "verde"
},
{
"nombre": "lkjlk",
"pais": "lmlk",
"sede": "lkjm"
}
]
How can I put that in a table? Thanks for your help.