I have a body onload calling a function in javascript. I Have tried many things, but the console just prints to the error log:
uncaught reference error: resetLoginForm is not defined
My code is as follows:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<title>Login Page</title>
<script src="/client/js/popper.min.js"></script>
<script src="/client/js/js.cookie.min.js"></script>
<script src="/client/js/querystring.js"></script>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" media="screen,projection"/>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<script type="module" src="js/login.js"></script>
</head>
<body class="blue-grey darken-2" onload="resetLoginForm()">
<script src="js/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
This is the JavaScript code that I am trying to use:
import * as Cookies from "/client/js/js.cookie.min.js";
function resetLoginForm() {
if (Cookies.get("destination") === undefined) {
window.location.href = "/client/index.html";
}
const loginForm = $('#loginForm');
loginForm.submit(event => {
event.preventDefault();
$.ajax({
url: '/admin/login',
type: 'POST',
data: loginForm.serialize(),
success: response => {
if (response.startsWith('Error:')) {
alert(response);
} else {
Cookies.set("sessionToken", response);
window.location.href = Cookies.get("destination");
}
}
});
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…