Ajax fade mesaj si redirect dupa un timp
Scris: Dum Mai 10, 2020
Am codul asta si vreau in loc de input type=button sa fie submit, dar sa imi dea fade la fel in 5 secunde de cand apare eroarea.
Daca schimb cu input type=submit imi apare pentru o secunda si dispare.
Dupa ce arata mesajul de succes vreau sa ma redirectioneze catre aceeasi pagina.
Daca schimb cu input type=submit imi apare pentru o secunda si dispare.
Dupa ce arata mesajul de succes vreau sa ma redirectioneze catre aceeasi pagina.
Cod: SelectaĊ£i tot
<form class="account-form" id="submit_form" method="post">
<span id="error_message" class="text-danger"></span>
<span id="success_message" class="text-success"></span>
<fieldset>
<i class="ti-key"></i>
<input type="password" name="pass" id="pass" placeholder="Password" />
</fieldset>
<input type="button" value="Login" id="submit" class="red-bg" />
</form>
</div>
<script>
$(document).ready(function(){
$('#submit').click(function(){
var pass = $('#pass').val();
if( pass == '')
{
$('#error_message').html("All Fields are required");
}
else
{
$('#error_message').html('');
$.ajax({
url:"/unlock",
method:"POST",
data:{pass:pass},
success:function(data){
$("form").trigger("reset");
$('#success_message').fadeIn().html(data);
setTimeout(function(){
$('#success_message').fadeOut("Slow");
}, 5000);
}
});
}
});
});
</script>