2
My need is as follows: write to a table, take the generated ID and write to the second table with this ID. As the order is to do this in jQuery, a function has been made (by a colleague). But unfortunately I cannot save.
See that there are two calls in AJAX. If I remove the second step (persist in the second table), the code works. But when I enable the second code, then nothing works, neither the first nor the second calls. Below my code jQuery. If I was going to do it in Code Behind, I would know how to do it, because I’ve done a lot, but with jQuery I’m not getting it.
$(function () {
$("#btnGravarPassageiros").click(function () {
var result = {
Id: 0,
Nome: $("input[name ='txtNome']").val(),
CPF: $("input[name='txtCep']").val(),
Email: $("input[name='txtEmail']").val(),
DataNascimento: $("input[name='txtAno']").val() + "-" + $("input[name='txtMes']").val() + "-" + $("input[name='txtDia']").val(),
Telefone: $("input[name='txtTelefone']").val(),
Celular: $("input[name='txtCelular']").val(),
Endereco: $("input[name='txtLogradouro']").val(),
Numero: $("input[name='txtNumero']").val(),
CEP: $("input[name='txtCep']").val(),
Complmento: $("input[name='txtComplemento']").val()
};
var result = [];
var resultado;
var cont = 0;
$.ajax({
url: '/Passo/addCliente',
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "POST",
data: JSON.stringify({ _tb_clientes: result }),
success: function (data) {
alert(data.Result);
$(".passageiro").each(function () {
nm = "txtNomePassageiro" + cont;
dia = "txtDiaPassageiro" + cont;
mes = "txtMesPassagecontro" + cont;
ano = "txtAnoPassagecontro" + cont;
sexo = "txtSexo" + cont;
numpassaporte = "txtPassaporte" + cont;
diavalidade = "txtDiaVal" + cont;
mesvalidade = "txtMesVal" + cont;
anovalidade = "txtAnoVal" + cont;
paisemissao = "txtPaisEmissao" + cont;
resultado = jQuery.parseJSON(
'{"Id_Cliente" : "' + data.Result +'" , "Nome": "' + $("input[name =" + nm + "]").val() +
'", "PassaPorte": "' + $("input[name =" + numpassaporte + "]").val() +
'", "DataNascimento": "' + $("input[name =" + dia + "-" + mes + "-" + ano + "]").val() +
'", "Sexo": "' + $("input[name =" + sexo + "]").val() + '", "PassaPorteValidade": "' +
$("input[name =" + diavalidade + "-" + mesvalidade + "-" + anovalidade + "]").val() +
'", "PassaPortePais": "' + $("input[name =" + paisemissao + "]").val() + '" }');
result.push(resultado);
cont++;
});
$.ajax({
url: '/Passo/addClientePassageiro',
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "POST",
data: JSON.stringify({ _tb_clientes: result }),
success: function (data) {},
error: function (error) {}
});
},
error: function (error) {}
});
});
});
People realized the following, that the recording function in my controller, works, at least in the first phase(1st table), but in BD is all null, as if recognizing the parameters passed from CSHTML. This is occurring.