Skip to content

Instantly share code, notes, and snippets.

@saharshg29
Created August 3, 2023 13:56
Show Gist options
  • Save saharshg29/d699ab0e5ef310fc83a038f7d3086c83 to your computer and use it in GitHub Desktop.
Save saharshg29/d699ab0e5ef310fc83a038f7d3086c83 to your computer and use it in GitHub Desktop.
This is main js file for previous html file
function validateLogin() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if (username === "" || password === "") {
alert("Please enter your username and password.");
return false;
}
var xhr = new XMLHttpRequest();
xhr.open("POST", "login.php");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("username=" + username + "&password=" + password);
xhr.onload = function() {
if (xhr.status === 200) {
window.location.href = "home.php";
} else {
alert("Login failed. Please try again.");
}
};
}
document.getElementById("login").onclick = validateLogin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment