PHP + Ajax Login

whole issue is in jquery use this instead

$(document).ready(function() {
  $('#loginform').submit(function(e) {
    e.preventDefault();
    $.ajax({
       type: "POST",
       url: '/class/login.php',
       data: $(this).serialize(),
       success: function(data)
       {
          if (data === 'Login') {
            window.location = '/user-page.php';
          }
          else {
            alert('Invalid Credentials');
          }
       }
   });
 });
});

 $user = new User(array("username" => $_POST['username'], "password" => $_POST['password']));
 $user->Login();

Put the code above into an login.php controller file (including your users class). Or write a general controller that handles the requests.


$(document).ready(function(){

 $("#submit").click(function(){
    var email = $("#email").val();
    var password = $("#password").val();

 if(email.length == "" || password.length == ""){
    $("#message").html("please fill out this field first").fadeIn();
    $("#message").addClass("error");
     return false;
}else{
    $.ajax({
      type : 'POST',
      url  : 'redirect.php',
      data : {email:email,password:password},
      success : function(feedback){
         $("#text").html(feedback);
       }
      });
   }
});

$(".email_error_text").hide();
$(".password_error_text").hide();

var error_email = false;
var error_password = false;


$("#email").focusout(function(){
  check_email();
});
$("#password").focusout(function(){
  check_password();
});


function check_email(){
    $("#message").hide();
var pattern = new RegExp(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
if(pattern.test($("#email").val())){
     $(".email_error_text").hide();
  }else{
     $(".email_error_text").html("Invalid email address");
     $(".email_error_text").show().addClass("error");
     error_email = true;
  }
}

function check_password(){
    $("#message").hide();
var password_length = $("#password").val().length;
if(password_length < 8 ){
     $(".password_error_text").html("Should be at least 8 characters");
     $(".password_error_text").show().addClass("error");
     error_password = true;
  }else{
     $(".password_error_text").hide();
  }
}

});

I will refer you to go here to read this article login with ajax & php