I have this div in my HTML:
Changes made:and I am going through a Javascript object, and I want to add some rows with the content of the Object, which is dynamic, the code I have is the following:
function pedirDatosTexto(ct){
var cam= JSON.parse(ct);
$.each(cam.cambios, function(x, it) {
var nombreTarjeta= it.nameCard;
var nombreLista= it.nameList;
var nombreListaNueva= it.nameListCambiada;
var tableObj = document.getElementById(tablaRes);
var celda= '" "nombreTarjeta+ " : "+ nombreLista+" Cambia a"+nombreListaNueva+" "';
});
};
I really don't know how you are bringing the data or how your table is structured, but in general terms, if you bring the file through an AJAX call , it would be something like this (it also applies to local calls):
Here I show you an example using a dynamically generated table.
Using an array to fill in the values of
TD
:Hello, it worked for me in the following way, in your HTML you enter the table in this way:
In this way we define the titles that will contain our columns (Title 1, Title2 etc...), in the id "MyTable" we will fill the columns with Javascript, making a query to our php file through AJAX, it will look like this:
We use a $.each to go through the AJAX response and we use the data brought through the "item" element, through the list variable we indicate that it will contain the element with id myTable, then we will create the tr element, the tr element will contain the th elements , which we create using the variables column1, column2 etc... and with column1.innerHTML = item.data1; we indicate what value or data that column will contain using the one brought from the query with item.dato1 or the name that the data has, finally we add the elements created with appendChild, first adding the tr to the variable list and then the columns to the variable tr so that they stay inside it.
I hope this is useful for you, regards.