Advertisement
Guest User

Untitled

a guest
Apr 5th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    
  2. function validate(event) {
  3.     event.preventDefault();
  4.     var form = document.forms["login"];
  5.     var userName = form.username.value;
  6.     var password = form.password.value;
  7.  
  8.     var data = {
  9.         username: "",
  10.         password: ""
  11.     };
  12.     data.username = userName;
  13.     data.password = password;
  14.     var xmlhttp = new XMLHttpRequest();
  15.     document.getElementById("error").innerHTML = "";
  16.     xmlhttp.onreadystatechange = function () {
  17.         console.info(xmlhttp.status + " " + xmlhttp.responseText);
  18.         if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  19.             window.location.href = "../src/homePage.php";
  20.             return;
  21.         } else if (xmlhttp.readyState == 4 && xmlhttp.status == 202) {
  22.             window.location.href = "../src/homePageAdmin.php";
  23.         } else if (xmlhttp.readyState == 4 && xmlhttp.status == 401) {
  24.             document.getElementById("error").innerHTML = xmlhttp.responseText;
  25.             return;
  26.         } else if (xmlhttp.readyState == 4 && xmlhttp.status == 404) {
  27.             document.getElementById("error").innerHTML = xmlhttp.responseText;
  28.             return;
  29.         }
  30.     }
  31.     xmlhttp.open("POST", "loginValidation.php", true);
  32.     xmlhttp.setRequestHeader("Content-Type", "application/json");
  33.     xmlhttp.send(JSON.stringify(data));
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement