I want to send html table data using ajax to servlet so that I can save it to mysql database, therefore my question is, I prepared the html data as an array and sent it to servlet that is ok, but the problem is while in servlet How can i get each value to save it to database. this is my code.
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
script type="text/javascript">
$(document).ready(function () { //launch this code after the whole DOM is loaded
$("form").submit(function (event) { // function to process submitted table
var a={};
var tableData = []; // we will store rows' data into this array
$("#adminTable") // select table by id
.find(".tableRow") // select rows by class
.has(":checked") // select only rows with checked checkboxes
.each(function () { // for each selected row extract data
var tableRow = {};
var jRow = $(this);
tableRow.customerId = jRow.find('td.customerId').text();
tableRow.customerType = jRow.find('td.customerType').text();
tableRow.customerKWH = jRow.find('td.customerKWH').text();
tableRow.costomerKWD = jRow.find('input.name1').val();
tableData.push(tableRow);
//alert(tableRow.costomerKWD);
});
$.post(
"generateKwd", /*url of consuming servlet*/
{tableData: tableData}, /*data*/
function () {
alert("Success!");
}, /*function to execute in case of success*/
"json" /* data type */
);
event.preventDefault(); //Prevent sending form by browser
}
);
});