assume that login.check() checks for validation of the fields after that I post the data to 'check.php' since it is an ajax request so to wait for the response I have taken a variable called flag(initialized with 'false'). When the response is processed I set the flag as 'true'. But, there is something is wrong with this script because the page freezes. But I cannot debug the script so please help me.
$('.login-form').submit(function(){
var flag = false , tag;
if(login.check() === false){
return false;
}
else{
$.post('check.php',{
"username":$('#username1').val(),
"password":$('#password1').val()
},function(data){
var obj = JSON.parse(data);
if(obj.status === false){
var server_alert = document.getElementsByClassName('server-alert')[0];
server_alert.innerHTML = obj.error;
server_alert.className = server_alert.className.replace('display-hide','');
tag = false;
flag = true;
}
else if(obj.status === true){
tag = true;
flag = false;
}
});
}
while(flag != true);
return tag;
})