Что не так с моей обработкой файла .e js методом POST? - PullRequest
0 голосов
/ 22 марта 2020

Это не сработает. Он просто говорит, что не может опубликовать это, а затем показывает путь. "Не удается POST /scripts/createAccount.js"

Почему это происходит и что я могу с этим сделать?

Это что-то с моим путем в моем коде или это что-то с моим кодом в моем POST-файле "createAccount. js"?

Это мой .e js файл ниже

<!DOCTYPE html>
<html lang="en">
<head>
    <script src="scripts/updateProfile.js" defer></script>
    <link href="style/stylesheet.css" type="text/css" rel="stylesheet">
    <meta http-equiv="Content-Type" const="text/html;charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Profile creation</title>
</head>
<body>
    <h1 id = "header">Profile creation</h1>
    <form id="account" action="./scripts/createAccount.js" method="POST">  
        <label for="uname">Username:</label><br>
        <input type="text" id="uname" name="pword"><br> <br>
        <label for="pword">Password:</label><br>
        <input type="password" id="pword" name="pword"> <br> 
        <input type="checkbox" onclick="myFunction()">Show Password <br> <br>
        <input type="radio" id="male" name="gender" value="male">
        <label for="male">Male</label><br>
        <input type="radio" id="female" name="gender" value="female">
        <label for="female">Female</label><br>
        <input type="radio" id="other" name="gender" value="other">
        <label for="other">Other</label>
        <p></p>
        <input id="button" type="submit"></button>
</form>
</body>
</html>

<style> 
#uname {
    margin-top: 8px;
    width: 200px;
}
#pword {
    margin-top: 8px;
    width: 200px;
}
#button {
    margin-top: 10px;
    width: 120px;
}
</style>

<script> 
    function myFunction() {
        let x = document.getElementById("pword");
        if (x.type === "password") {
        x.type = "text";
        } else {
        x.type = "password";
        }
  }
</script>

Это мой файл, чтобы попытаться получить данные, используя POST

let express = require('express');  
let app = express();  
let bodyParser = require('body-parser');  
// Create application/x-www-form-urlencoded parser  
let urlencodedParser = bodyParser.urlencoded({ extended: false })  
app.use(express.static('public'));  
app.get('/Profile.ejs', function (req, res) {  
   res.sendFile( scripts + "/" + "Profile.ejs" );  
})  
app.post('/process_post', urlencodedParser, function (req, res) {  
   // Prepare output in JSON format  
   response = {  
       first_name:req.body.first_name,  
       last_name:req.body.last_name  
   };  
   console.log(response);  
   res.end(JSON.stringify(response));  
})  
let server = app.listen(8000, function () {  
  let host = server.address().address  
  let port = server.address().port  
  console.log("app listening at http://%s:%s", host, port)  
})  

Это имена файлов

...