$(document).ready(function() { $("#myform").submit(function(event) { event.preventDefault(); // console.log($("#myform").serialize()); checkpasswd($("#myform").serialize()); // }); }); function checkpasswd(data) { // console.log(data); $.post('php/checkpasswd.php', data, function(retdata){ if (retdata.valid == true) { //successfully logged in sessionStorage.LAST_ACTIVITY = Math.round(new Date().getTime() / 1000); document.cookie = "LAST_ACTIVITY="+Math.round(new Date().getTime() / 1000); window.location ="movies.php"; return true; }else { $(".mypassalert").show(); setTimeout(function () { $(".mypassalert").hide(); }, 2000); } },'json'); }