为什么我不能获得帖子参数?

时间:2017-05-15 09:10:29

标签: node.js

这是我的HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Page d'inscription/connexion</title>
</head>
<body>
<form method="POST" action="/join" enctype="multipart/form-data">
  Pseudo:<br>
  <input type="text" name="pseudo"><br>
  <input type="submit" value="S'inscrire">
</form>
</body>
</html>

这是我的nodeJs

var express = require("express");


 //use the application off of express.
 var app = express();

 var bodyParser = require('body-parser');
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies


 //define the route for "/"
 app.get("/", function (request, response){
    console.log("aaa")
     response.sendFile(__dirname+"/index.html");
 });

 app.post("/join", function (request, response){
     var pseudo = request.body.pseudo;

     console.log(pseudo)

     if (pseudo != "") {
         response.send("Your pseudo address is " + pseudo + " ");
     } else {
         response.send("Please provide us pseudo");
     }
 });

 //start the server
 app.listen(8080);

 console.log("Something awesome to happen at http://localhost:8080");

为什么,当我把&#34;先生杜邦&#34; as伪,然后我提交按钮,伪是未定义而不是杜邦先生? 请帮帮我,我被封锁了

1 个答案:

答案 0 :(得分:1)

只需删除enctype="multipart/form-data"即可。