Good evening developers I am trying to save a record in my database using ajax, jquery although I am somewhat stuck on how to start there, I received a tip using this code:
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Pantalla Opciones</title>
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<link href="~/Styles.css" rel="stylesheet" />
<script src="~/Scripts/jquery-3.3.1.min.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
</head>
<body>
<div class="row">
@if (ViewData["Motivos"] != null)
{
foreach (var motivo in (List<EntradaElectronicaAlmacen.Models.Dtos.Motivo>)ViewData["Motivos"])
{
<div class="col-sm-3">
<button id="@motivo.Motivo_Id.ToString()-btn" class="boton3d5 clMotivo" data-id="@motivo.Motivo_Id" data-toggle="modal" data-target="#PopUpAcceso">
@motivo.Descripcion
</button>
</div>
}
}
</div>
<script>
var fa = new Date().toLocaleDateString();
$("#txtFecha").val(fa);
var ha = new Date().toLocaleTimeString();
$("#txtHoraEntrada").val(ha);
$("#txtGafete").keypress(function (e) {
if (e.keyCode === 13) {
var gafete = $("#txtGafete").val();
var mm;
$.ajax({
url: "http://localhost:49851/api/empleadoAutorizado/" + gafete,
method: "GET",
contentType: "application/json",
success: function (data) {
if (data == null) {
ocultarPopUp();
} else {
$("#txtNombre").val(data.nombre);
}
}
});
}
});
</script>
</body>
</html>
The save function must be completed by clicking on the button that can be seen in the boby, I just need a guide using ajax, the one that I see the keyPress I am using it to consume some data in the view, they told me that it can be do something similar also to save but I do not have much experience using ajax and jquery.