so this is my code ,i am a beginner at js and i am trying to learn it by making some thing , this is the code where i am trying to validate user by password by checking with server side admin password ,
when i try importing export.js function and set the type to module it just refreshes , i didnt face this problem with other pages , please help me
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../css/styles.css">
</head>
<body>
<div class="container">
<form name="loginForm" method="post" action="./admin.html">
<input type="text" size="25" name="userid" placeholder="Enter username" required>
<input type="password" size="25" name="pwd" placeholder="Enter password" required>
<button type="reset">Reset</button>
<button type="submit" onclick="return check(this.form)">Login</button>
</form>
</div>
</body>
<!-- this works -->
<script src="../js/admin_login.js"></script>
<!-- this doesnot work -->
<!-- <script src="../js/admin_login.js" type="module"></script> -->
</html>
admin_login.js
// REFERENCE OF THIS FILE: ttps://stackoverflow.com/questions/74308397/javascript-login-username-password
//this works
async function check(form) {
const username = form.userid.value;
const password = form.pwd.value;
if (username === "test" && password === "test") {
sessionStorage.setItem("authenticated", "true");
window.location.href = "admin.html";
return false;
} else {
alert("Invalid username or password. Please try again.");
return false;
}
}
// Doesnot work
// import { get } from "../server/credentials/export.js";
// //second answer
// function check(form) {
// const username = form.userid.value;
// const password = form.pwd.value;
// validate(password)
// }
// async function validate(password){
// var address = await get();
// var res = await fetch(`${address}/login/${password}`, {
// method: "GET",
// headers: {
// "Content-Type": "application/json",
// }
// });
// if (res.status == 200){
// sessionStorage.setItem("authenticated", "true");
// window.location.href = "admin.html";
// return false;
// }
// else{
// alert("Invalid username or password. Please try again.");
// return false;
// }
// }
export.js
async function get(){
var response = await fetch('../server/credentials/get.txt')
var data = await response.text()
return data;
}
async function post(){
var response = await fetch('../server/credentials/post.txt')
var data = await response.text()
return data;
}
export {get,post}