Pasted below is my code. When the #login_form is submitted, it would pass the username and the password from the form to the php file in the 'c_login' pathway. The data that is returned is either 1, or a String error response. The problem I have right now is that
although the response is set to 'true' in the else statement when the data is returned as 1,
the response still remains as 'false' unless I submit the form again. The response, I think, is changed at the else statement, but the 'response' that is being returned at the very end of the code has not been synched to the change. How can I edit this so that the user does not have to double click the 'submit' button in order to log in?
var c_login = '../../../scripts/check_login.php';
var response = false;
$(document).ready(function(){
$('#login_form').submit(function(){
alert(response);
$.post(c_login, {username: $.trim(login_form.username.value), password: login_form.password.value}, function(data){
if(data!=1)
$('.status').html(data);
else{
response = true;
alert('response changed to true');
}
});
return response; //response returns 'false' the first time the else statement is executed.
});
});