$(document).ready(function() { $("#formLogin").submit(function(event) { if(checkconnection()){ var formData = { email: $("#email").val(), password: $("#password").val(), from: $("#from").val(), event: $("#event").val() }; $.ajax({ type: "POST", url: "json.php?jsonData=login", data: formData }).done(function(data) { var json = $.parseJSON(data); if(!json.success) { $("#divAlerte").empty(); $("#divAlerte").html(''); $("#divAlerte").show(); window.setTimeout(function() { $("#divAlerte").fadeTo(600, 0).slideUp(600, function(){ $(this).hide(); $(this).css('opacity', '1'); }); }, 1000); } else { window.location = "/home.php"; } }); event.preventDefault(); } else { event.preventDefault(); $("#divAlerte").empty(); $("#divAlerte").append(''); $("#divAlerte").show(); window.setTimeout(function() { $("#divAlerte").fadeTo(600, 0).slideUp(600, function(){ $(this).hide(); $(this).css('opacity', '1'); }); }, 1000); } }) });