Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function validate(event) {
- event.preventDefault();
- var form = document.forms["login"];
- var userName = form.username.value;
- var password = form.password.value;
- var data = {
- username: "",
- password: ""
- };
- data.username = userName;
- data.password = password;
- var xmlhttp = new XMLHttpRequest();
- document.getElementById("error").innerHTML = "";
- xmlhttp.onreadystatechange = function () {
- console.info(xmlhttp.status + " " + xmlhttp.responseText);
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
- window.location.href = "../src/homePage.php";
- return;
- } else if (xmlhttp.readyState == 4 && xmlhttp.status == 202) {
- window.location.href = "../src/homePageAdmin.php";
- } else if (xmlhttp.readyState == 4 && xmlhttp.status == 401) {
- document.getElementById("error").innerHTML = xmlhttp.responseText;
- return;
- } else if (xmlhttp.readyState == 4 && xmlhttp.status == 404) {
- document.getElementById("error").innerHTML = xmlhttp.responseText;
- return;
- }
- }
- xmlhttp.open("POST", "loginValidation.php", true);
- xmlhttp.setRequestHeader("Content-Type", "application/json");
- xmlhttp.send(JSON.stringify(data));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement