javascriptcssnode.jsexpress

Why doesnt my website sub url working when submitting form but works when i manually enter it


I have a form on localhost:8080 which when you enter form data (user & pass), then press submit, it meant to send a POST to localhost:8080/submit, then should show text on that page saying "Submit page". When I enter "localhost:8080/submit" into my browser, it works, but when I use the submit button to get there, it says "This site can’t provide a secure connection" (aka, doesn't work)

script.js

const url = "https://localhost:8080";
const data = {
    "user": "user",
    "pass": "pass"
}

function send() {
    alert("Sent")
    $.post(url, data, function (data, status) {
        console.log("Sent " + data + ", status is: " + status)
    });
}
body {
    background-color: #444444;
}

.form-div {
    width: 100%;
    height: auto;
    text-align: center;
    justify-content: center;
    align-content: center;
    border: 1px solid red;
}

form {
    color: white;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Harley Swift</title>
    <link rel='stylesheet' href='styles.css'/>
    <script type="text/javascript" src="script.js"></script>
</head>

<body>
<div class="form-div">
    <form method="POST" action="https://localhost:8080/submit">
        <div>
            <label for="user">Username</label>
            <input name="user" type="text" id="user"><br>
        </div>

        <div>
            <label for="pass">Password</label>
            <input name="pass" type="password" id="pass"><br>
        </div>
        <br>
        <div>
            <button class="btn" onclick="send()">Submit</button>
        </div>
    </form>
</div>
</body>
</html>

app.js: https://hastebin.com/udunalurub.lua (couldn't figure out how to use code snippets on here, sorry)

Thank you in advance! I am not too familiar with nodejs servers yet


Solution

  • Don't use https, use http when developing locally.