简体   繁体   中英

How to pass a table data from and HTML front end to the server side in Django through JSON?

I have multiple tables in the front end. Based on the information provided in the table an oracle database needs to be updated at the back end. The server side is coded in Django and the front end is the typical HTML, Javascript, Bootstrap, Jquery etc. The data is needed to be passed as JSON request since the application sends data to the server side in a JSON format. The question is how to parse the table in the front end, encompass it in an object and send it through JSON and parse it in Python( Django )?

My plan is to store the values in a javascript object and then pass it in json format. By I am unable to iterate over the values of the table itself.

var exclScoreObj = new Object();
$("#exclTable tr").each(function() {
    $(this).find('td').each(function(){
        console.log($(this).val())
    })
})

I could do it without using jquery. I would very much like an answer on how to do it in jquery. But by simply using javascript this is how I could get the table values.

var table = document.getElementById("xxxx");
for (var i = 0, row; row = table.rows[i]; i++) {
   for (var j = 0, col; col = row.cells[j]; j++) {
      console.log(col.childNodes[0].value);
   }  
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM