I'm trying to perform a bootstrap alert. it is displayed correctly when the response is received correctly, or some error. but when I perform another action that involves another ajax response, this one no longer shows me the alert.
Here is my index.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>Inicio</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<!-- zqui dibujo el alert -->
<div id="alertDiv"></div>
</body>
</html>
in my javascript file.
$.ajax({
url: "ToAjax.php",
type: "POST",
data: fd,
contentType: false,
processData:false,
success: function(data){
var json = $.parseJSON(data);
console.log(json);
$('#frmNewProduct').trigger('reset');
$('#modalProduct').modal('toggle');
// aqui dibujo el alert
$('#alertDiv').append(
'<a href="#" class="close" data-dismiss="alert">×</a>'
)
.addClass("alert alert-success fade in")
.append('<strong>' + json.message + '!</strong> Your message has been sent successfully.');
},
error: function(data){
var json = $.parseJSON(data);
$('#modalProduct').modal('toggle');
}
});
});
};
It is worth mentioning that the data came from a modal. and upon successful registration, this closes.
but the alert is only drawn once. I have to refresh the page for when I make another insert this draw the alert. the requests are successful, so my problem is in front end. Maybe the way I'm drawing it. I do not know if it's the right one. someone to guide me Greetings!