Created
August 3, 2023 13:56
-
-
Save saharshg29/d699ab0e5ef310fc83a038f7d3086c83 to your computer and use it in GitHub Desktop.
This is main js file for previous html file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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