““ post”请求不起作用,浏览器说无法读取未定义的属性'crypto'
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.get(bodyParser.urlencoded({extended: true}));
app.get("/", function(req, res){
res.sendFile(__dirname + "/index.html");
});
app.post("/", function(req, res){
console.log(req.body.crypto);
});
app.listen(3000, function(){
console.log("server is running in port 3000");
});
回答如下:您的req.body
未定义,
您必须填写此行
app.get(bodyParser.urlencoded({extended: true}));
到
app.use(bodyParser.urlencoded({extended: true}));
““ post”请求不起作用,浏览器说无法读取未定义的属性'crypto'
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.get(bodyParser.urlencoded({extended: true}));
app.get("/", function(req, res){
res.sendFile(__dirname + "/index.html");
});
app.post("/", function(req, res){
console.log(req.body.crypto);
});
app.listen(3000, function(){
console.log("server is running in port 3000");
});
回答如下:您的req.body
未定义,
您必须填写此行
app.get(bodyParser.urlencoded({extended: true}));
到
app.use(bodyParser.urlencoded({extended: true}));
评论列表 (0)
- 暂无评论