I have the following problem using sweet alert and modal bootstrap. It turns out, I make the requests through ajax and php, but the generated alert always shows me the independent success if the request to the server was successful or not. What I need is that if the request is successful, show the success, otherwise show error. The code that I leave here, is how I have it now. I have tried in many ways and none of them work and I also generated errors, that is why I only write the success of the procedure:
$(document).ready(function(){
$('#edit_nomen').submit(function(e){
e.preventDefault();
var datos = $(this).serialize();
$.ajax({
type:"POST",
url: "miarchivo.php",
data : datos,
success:function(data){
$('.modal').modal('hide');
swal(
'ALGUN TEXTO',
'OTRO TEXTO',
'success'
);
$('#respuesta').html(data);
$('#listado').DataTable().ajax.reload();
}
});
});
});
I am using SweetAlert2. It is worth mentioning that this procedure is performed on a modal window. I appreciate any help or guidance that you can give me. Greetings to all.