here is my code
$('#login').on('click',function(e){
e.preventDefault();
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
var ajax = new XMLHttpRequest();
var vars = 'username='+username+'&password='+password;
var url = "singInDrProcess.php";
ajax.open("POST", url, true);
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajax.send(vars);
ajax.onreadystatechange = function() {
if(ajax.readyState == 4 && ajax.status == 200) {
var return_data = ajax.responseText;
if(return_data!="success_login")
document.getElementById("result_signin").innerHTML = return_data;
}else{
window.location.replace("profile.php");
}
}
});
The problem is , when user comes to this page and tries to Login, even if he never enters any username or password, and just clicks on my login button, page will be redirected to profile.php I mean, the ELSE part always runs, either there is data on fields or all of them are empty what is the problem?
replacefunction likewindow.location.replace("http://example.com/profile.php);