How to serialize the data of an HTML table and send it through Ajax?

-1

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

    
asked by Eduardol Rivas 30.01.2018 в 00:40
source

2 answers

-1
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)+'}');
    
answered by 30.01.2018 / 04:23
source
-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.

    
answered by 30.01.2018 в 00:59