0
I have a table tbLista
html with some values filled and wanted to read it by JS, my Js code is of the second way:
var rowIndex = -1;
var beneficiarios = [];
$(document).ready(function () {
$('#formCadastro').submit(function (e) {
e.preventDefault();
var lista = document.getElementById('tbLista').rows;
for (var i = 1; i < lista.length; i++) {
beneficiarios.push(JSON.stringify({ "cpf": lista[i].cells[0].innerHTML, "nome": lista[i].cells[1].innerHTML }));
}
$.ajax({
url: urlPost,
method: "POST",
data: {
"NOME": $(this).find("#Nome").val(),
"CEP": $(this).find("#CEP").val(),
"Email": $(this).find("#Email").val(),
"Sobrenome": $(this).find("#Sobrenome").val(),
"Nacionalidade": $(this).find("#Nacionalidade").val(),
"Estado": $(this).find("#Estado").val(),
"Cidade": $(this).find("#Cidade").val(),
"Logradouro": $(this).find("#Logradouro").val(),
"Telefone": $(this).find("#Telefone").val(),
"Cpf": $(this).find("#Cpf").val(),
"Beneficiarios": JSON.stringify(beneficiarios)
},
error:
function (r) {
if (r.status == 400)
ModalDialog("Ocorreu um erro", r.responseJSON);
else if (r.status == 500)
ModalDialog("Ocorreu um erro", "Ocorreu um erro interno no servidor.");
},
success:
function (r) {
ModalDialog("Sucesso!", r)
$("#formCadastro")[0].reset();
}
});
});
});
Html:
<div class="row">
<div class="col-lg-5">
<div class="form-group">
<label for="CpfBeneficiario">CPF:</label>
<input type="text" class="form-control" id="CpfBeneficiario" name="CpfBeneficiario" placeholder="Ex.: 010.011.111-00" maxlength="14">
</div>
</div>
<div class="col-lg-5">
<div class="form-group">
<label for="NomeBeneficiario">Nome:</label>
<input type="text" class="form-control" id="NomeBeneficiario" name="NomeBeneficiario" placeholder="Ex.: João" maxlength="50">
</div>
</div>
<div class="col-lg-2">
<div class="pull-right">
<button id="btnIncluir" type="button" onclick="AddBeneficiarios();" class="btn btn-sm btn-success" style="margin-top: 45%">Incluir</button>
</div>
</div>
</div>
<table id="tbLista" class="table">
<thead>
<tr>
<th>
@Html.DisplayName("CPF")
</th>
<th>
@Html.DisplayName("Nome")
</th>
<th></th>
</tr>
</thead>
<tbody>
<tbody>
</table>
How to do?
without displaying html will not help
– Ricardo Pontual
post all your code so we can help you better, hug
– user148170
@Ricardopunctual Posted the HTML
– Stand Alone