PHP and js Login Script

How To Write Ajax Request in js file for Login form

$("#loginBtn").click(function () {
    var httpLoginRequest=new XMLHttpRequest();
    httpLoginRequest.onreadystatechange = function () {
        if(httpLoginRequest.readyState == 4 && httpLoginRequest.status == 200) {
            if (httpLoginRequest.responseText == "Idetified") {
                window.location.href = 'main.html';   
         }else if(httpLoginRequest.responseText == "Cannot Identify") {
                alert(this.responseText);  
             return;        
    }
        }
    };
    httpLoginRequest.open('POST',"pages/getLoginPHP.php",true);  

  httpLoginRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    var queryString1=$("#formLogin").serialize();
    httpLoginRequest.send(queryString1);});

No comments:

Post a Comment