Good afternoon colleagues, I have a question about how I could serialize the content of an HTML table and then send it via ajax to the controller of my application in MVC5
Good afternoon colleagues, I have a question about how I could serialize the content of an HTML table and then send it via ajax to the controller of my application in MVC5
var json="";
$(document).ready(function () {
$(".guardar").on("click",function () {
$(".trjson").each(function () {
json ="";
$(this).find("th").each(function () {
$this=$(this);
json+=',"'+$this.attr("class")+'":"'+$this.html()+'"'
});
obj=JSON.parse('{'+json.substr(1)+'}');
It occurs to me that you could go through the Tr of your Table by getting each Td and build an object with them.
var objeto = [];
$("#mitabla tr").each(function() {
var tds = $("td", $(this));
objeto.push({
column1: tds[0].text(),
column2: tds[1].text()
});
});
It is a very simple example but it is to give you an idea of how you could do it, try it and if you need help stick the code you already have and we can see what can be done.