I have a link with your respective href that wants to send data to the server but I use prevent to ask if I'm sure, if I give it IF I thought that I should send the communication with the server but not do anything, but if I relocate it works
$(function() {
$('.envios').click(function(e) {
e.preventDefault();
swal({
title: "Aviso",
text: "Está seguro que desea salir ? ",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
//Mensaje Opcional
swal("Usted será redireccionado", {
icon: "success",
});
console.log(this.href);
// redirección location.href = this.href
} else {
swal("Canceceló la acción");
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<a href='envaluacion/primera' class="envios">Irse</a>
<a href='envaluacion/segunda' class="envios">Irse a Otra</a>
when I use ajax, it redirects me, but why and how do I fix it?
$('.btnDeletes').on('click', function(e) {
e.preventDefault();
var nombreEva = 'evaDinamica';
var idSalida = this.id;
console.log('LÑ', idSalida);
swal({
title: "Esta seguro de eliminar al usuario?",
text: "Elija una opcion",
icon: "warning",
buttons: true,
dangerMode: true,
}).then((willDelete) => {
if (willDelete) {
$.ajax({
url: "/evaluacion/concerderRsol/" + nombreEva + "/" + id,
type: "GET",
data: {
nombreEva: nombreEva,
user: id
},
dataType: "html",
success: function() {
console.log('success');
swal("si!", "bien", "success");
},
error: function(xhr, ajaxOptions, thrownError) {
console.log('error');
swal("Error!", "Please try again", "error");
}
});
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<button class="btnDeletes" id="uno">enviar</button>